Java List Intersect calculauteIntersection(Set wordList1, Set wordList2)

Here you can find the source of calculauteIntersection(Set wordList1, Set wordList2)

Description

calculaute Intersection

License

Apache License

Declaration

public static boolean calculauteIntersection(Set<String> wordList1, Set<String> wordList2) 

Method Source Code

//package com.java2s;
/**/*from w w  w  .j ava  2  s  . c o  m*/
 * 
 * Copyright (c) 2012 - 2014 Carnegie Mellon University
 * 
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at
    
  http://www.apache.org/licenses/LICENSE-2.0
    
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License.
 * 
 * @author Chaitra Radhakrishna, Language Technology Institute, School of Computer Science, Carnegie-Mellon University.
 * email: wei.zhang@cs.cmu.edu
 *
 * 
 */

import java.util.HashSet;
import java.util.Iterator;

import java.util.Set;

public class Main {
    public static boolean calculauteIntersection(Set<String> wordList1, Set<String> wordList2) {
        Set<String> allWords = populateWordset(wordList1, wordList2);

        // int M11 = 0;

        Iterator<String> wordList = allWords.iterator();
        while (wordList.hasNext()) {
            String word = wordList.next();
            boolean freq1 = wordList1.contains(word);
            boolean freq2 = wordList2.contains(word);

            if (freq1 && freq2) {
                return true;
            }
        }

        return false;
    }

    static Set<String> populateWordset(Set<String> wordList1, Set<String> wordList2) {
        Set<String> allWords = new HashSet<String>();

        Set<String> wordIterator = null;
        Iterator<String> iterator = null;

        // wordIterator = wordList1.keySet();
        iterator = wordList1.iterator();

        while (iterator.hasNext()) {

            allWords.add(iterator.next());

        }
        // wordIterator = wordList2.keySet();
        iterator = wordList2.iterator();
        while (iterator.hasNext()) {

            allWords.add(iterator.next());

        }

        return allWords;
    }
}

Related

  1. calcIntersection(List a, List b)
  2. getIntersection( final List... collectionOfIDLists)
  3. getIntersection(List list1, List list2)
  4. getIntersection(String[] list1, String[] list2)
  5. getIntersectionOfLineAndSegments(double x1, double y1, double x2, double y2, List segmentPoints)