Java Code Examples for gnu.trove.set.hash.THashSet#size()

The following examples show how to use gnu.trove.set.hash.THashSet#size() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JaccardSimilarity.java    From fnlp with GNU Lesser General Public License v3.0 5 votes vote down vote up
public float calc(THashSet<Object> s1, THashSet<Object> s2) {
    int com = 0;
    if (s1 == null || s2 == null)
        return 0;
    TObjectHashIterator<Object> it = s1.iterator();
    for ( int i = s1.size(); i-- > 0; ) {
        Object v = it.next();
        if(s2.contains(v))
            com++;
    }
    float sim = ((float) com)/(s1.size()+s2.size()-com);
    return sim;
}
 
Example 2
Source File: CWSTagger.java    From fnlp with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * 设置词典
 * @param newset
 */
public void setDictionary(THashSet<String> newset) {
	if(newset.size()==0)
		return;
	ArrayList<String> al = new ArrayList<String>();
	MyCollection.TSet2List(newset, al);
	Dictionary dict = new Dictionary();
	dict.addSegDict(al);
	setDictionary(dict);

}
 
Example 3
Source File: DFDMiner.java    From metanome-algorithms with Apache License 2.0 4 votes vote down vote up
private Stack<Seed> nextSeeds(int currentRHSIndex) {
//		System.out.println("Find holes");
		THashSet<ColumnCollection> deps = new THashSet<>();
		ArrayList<ColumnCollection> currentMaximalNonDependencies = maximalNonDependencies.getLHSForRHS(currentRHSIndex);
		HashSet<ColumnCollection> currentMinimalDependencies = new HashSet<>(minimalDependencies.getLHSForRHS(currentRHSIndex));
		ArrayList<ColumnCollection> newDeps = new ArrayList<>(numberOfColumns * deps.size());
//		Holes holes = new Holes();
		
//		int i = 0;
//		for (ColumnCollection maximalNonDependency : currentMaximalNonDependencies) {
//			ColumnCollection complement = maximalNonDependency.setCopy(currentRHSIndex).complement();
//			if (deps.isEmpty()) {
//				ColumnCollection emptyColumnIndices = new ColumnCollection(numberOfColumns);
//				for (Integer complementColumnIndex : complement.getSetBits()) {
//					deps.add(emptyColumnIndices.setCopy(complementColumnIndex));
//				}
//			} else {
//				for (ColumnCollection dep : deps) {
//					int[] setBits = complement.getSetBits();
//					for (int setBit = 0; setBit < setBits.length; setBit++) {
//						holes.add(dep.setCopy(setBits[setBit]));
////						System.out.println("Dep:\t" + dep.setCopy(setBits[setBit]));
//					}
//				}
//				// minimize newDeps
//				System.out.println(i++ + "\t" + currentMaximalNonDependencies.size());
//				System.out.println("total deps:\t" + deps.size());
//				System.out.println("before minimizing:\t" + holes.size());
////				ArrayList<ColumnCollection> minimizedNewDeps = minimizeSeeds(newDeps);
//				holes.minimize();
//				System.out.println("after minimizing:\t" + holes.size());
//				deps.clear();
//				deps.addAll(holes);
//				holes.clear();
//			}
//		}

		for (ColumnCollection maximalNonDependency : currentMaximalNonDependencies) {
			ColumnCollection complement = maximalNonDependency.setCopy(currentRHSIndex).complement();
			if (deps.isEmpty()) {
				ColumnCollection emptyColumnIndices = new ColumnCollection(numberOfColumns);
				for (int complementColumnIndex : complement.getSetBits()) {
					deps.add(emptyColumnIndices.setCopy(complementColumnIndex));
				}
			} else {
				for (ColumnCollection dep : deps) {
					int[] setBits = complement.getSetBits();
					for (int setBit = 0; setBit < setBits.length; setBit++) {
						newDeps.add(dep.setCopy(setBits[setBit]));
					}
				}
				// minimize newDeps
				ArrayList<ColumnCollection> minimizedNewDeps = minimizeSeeds(newDeps);
				deps.clear();
				deps.addAll(minimizedNewDeps);
				newDeps.clear();
			}
		}
		
		// return only elements that aren't already covered by the minimal
		// dependencies
		Stack<Seed> remainingSeeds = new Stack<>();
		deps.removeAll(currentMinimalDependencies);
		for (ColumnCollection remainingSeed : deps) {
			remainingSeeds.push(new Seed(remainingSeed));
		}

		return remainingSeeds;
	}
 
Example 4
Source File: RLSeg.java    From fnlp with GNU Lesser General Public License v3.0 4 votes vote down vote up
int update(String[] toks) throws IOException {
	if(toks==null)
		return 0;
	THashSet<String> newdict = new THashSet<String>();
	String nowords = "";
	int count = 0;
	for(int i=0;i<toks.length;i++){//取得包含新词的最长子串
		if(Chars.isLetterOrDigitOrPunc(toks[i]))
			continue;

		if(!dict.contains(toks[i])&&!tempdict.contains(toks[i])){
			nowords += "" + toks[i];
			count++;
		}else{
			if(nowords.length()>0){
				System.out.println(nowords);
				newdict.add(nowords.trim());
				nowords = "";
			}
		}
	}


	TObjectHashIterator<String> it = newdict.iterator();
	while(it.hasNext()){
		String s = it.next();
		if(nodict.contains(s))
			continue;
		System.out.println("搜索: "+s);
		THashSet<String> sset = getNewWords(s);
		if(sset==null||sset.size()==0)
			continue;
		System.out.println(sset);
		tempdict.addAll(sset);
		if(!sset.contains(s)&&!nodict.contains(s)){
			nodict.add(s);
			bwNo.write(s);
			bwNo.write("\n");
		}

	}
	bwNew.flush();
	bwNo.flush();
	return count;
}