gnu.trove.set.hash.THashSet Java Examples

The following examples show how to use gnu.trove.set.hash.THashSet. 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: Util.java    From CQL with GNU Affero General Public License v3.0 6 votes vote down vote up
public static <T> Set<Set<T>> powerSet(Collection<T> originalSet) {
	Set<Set<T>> sets = new THashSet<>((int) Math.pow(2, originalSet.size()));
	if (originalSet.isEmpty()) {
		sets.add(Collections.emptySet());
		return sets;
	}
	List<T> list = new ArrayList<>(originalSet);
	T head = list.get(0);
	Set<T> rest = new THashSet<>(list.subList(1, list.size()));
	for (Set<T> set : powerSet(rest)) {
		Set<T> newSet = new THashSet<>(set.size() + 1);
		newSet.add(head);
		newSet.addAll(set);
		sets.add(newSet);
		sets.add(set);
	}
	return sets;
}
 
Example #2
Source File: LPOUKB.java    From CQL with GNU Affero General Public License v3.0 6 votes vote down vote up
private Quad<Map<V, KBExp<C, V>>, Map<V, KBExp<C, V>>, Map<V, V>, Map<V, V>> freshenMap(Iterator<V> fresh,
		Triple<KBExp<C, V>, KBExp<C, V>, Map<V, T>> eq) {
	Set<V> vars = new THashSet<>();
	KBExp<C, V> lhs = eq.first;
	KBExp<C, V> rhs = eq.second;
	vars.addAll(lhs.getVars());
	vars.addAll(rhs.getVars());
	Map<V, KBExp<C, V>> subst = (new THashMap<>());
	Map<V, KBExp<C, V>> subst_inv = (new THashMap<>());
	Map<V, V> subst1 = (new THashMap<>());
	Map<V, V> subst_inv1 = (new THashMap<>());
	for (V v : vars) {
		V fr = fresh.next();
		subst.put(v, kb.factory.KBVar(fr));
		subst_inv.put(fr, kb.factory.KBVar(v));
		subst1.put(v, fr);
		subst_inv1.put(fr, v);
	}
	return new Quad<>(subst, subst_inv, subst1, subst_inv1);
}
 
Example #3
Source File: Collage.java    From CQL with GNU Affero General Public License v3.0 6 votes vote down vote up
public static <Ty, En, Sym, Fk, Att, Gen, Sk> boolean defn(Map<Var, Chc<Ty, En>> ctx,
		Term<Ty, En, Sym, Fk, Att, Gen, Sk> lhs, Term<Ty, En, Sym, Fk, Att, Gen, Sk> rhs) {
	if (lhs.var != null || lhs.obj() != null) {
		return false;
	}
	List<Var> vars = getVarArgsUnique(lhs);
	if (vars == null) {
		return false; // f(x,x) kind of thing
	}
	if (!new THashSet<>(vars).equals(ctx.keySet())) {
		return false; // forall x, y. f(y) = ... kind of thing
	}

	Head<Ty, En, Sym, Fk, Att, Gen, Sk> head = Head.mkHead(lhs);
	if (!rhs.contains(head)) {
		return true;
	}
	return false;
}
 
Example #4
Source File: LPOUKB.java    From CQL with GNU Affero General Public License v3.0 6 votes vote down vote up
private void simplify() {
	Map<KBExp<C, V>, KBExp<C, V>> cache = new THashMap<>();

	List<Triple<KBExp<C, V>, KBExp<C, V>, Map<V, T>>> newE = new LinkedList<>();
	Set<Triple<KBExp<C, V>, KBExp<C, V>, Map<V, T>>> newE2 = new THashSet<>();
	for (Triple<KBExp<C, V>, KBExp<C, V>, Map<V, T>> e : E) {
		KBExp<C, V> lhs_red = red(this::gtX, cache, new LinkedList<>(), R, e.first, e.third.values());
		KBExp<C, V> rhs_red = red(this::gtX, cache, new LinkedList<>(), R, e.second, e.third.values());
		if (!lhs_red.equals(rhs_red)) {
			Triple<KBExp<C, V>, KBExp<C, V>, Map<V, T>> p = new Triple<>(lhs_red, rhs_red, e.third);
			if (!newE2.contains(p)) {
				newE.add(p);
				newE2.add(p);
			}
		}
	}
	E = newE;
}
 
Example #5
Source File: WordSimilarity.java    From fnlp with GNU Lesser General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
public void calSimilarity(String outpath) throws Exception {
    BufferedWriter bout = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outpath), "UTF-8"));
    for (int i = 0; i < hashlist.size(); i++)
        bout.write("\t" + word.get(i));
    bout.write("\n");
    for (int i = 0; i < hashlist.size(); i++) {
        bout.write(word.get(i) + "\t");
        for (int j = 0; j < hashlist.size(); j++) {
            float f = is.calc((THashSet<String>)hashlist.get(i), (THashSet<String>)hashlist.get(j));
            f = (float)(Math.round(f * 1000)) / 1000;
            bout.write(f + "\t");
        }
        bout.write("\n");
    }
    bout.close();
}
 
Example #6
Source File: LPOUKB.java    From CQL with GNU Affero General Public License v3.0 6 votes vote down vote up
private static <T, C, V> Pair<Map<V, KBExp<C, V>>, Map<V, KBExp<C, V>>> freshenMap(KBTheory<T, C, V> kb,
			Iterator<V> fresh, Pair<KBExp<C, V>, KBExp<C, V>> eq) {
		Set<V> vars = (new THashSet<>());
		KBExp<C, V> lhs = eq.first;
		KBExp<C, V> rhs = eq.second;
		lhs.vars(vars);
		rhs.vars(vars);
//		vars.addAll(lhs.vars());
//		vars.addAll(rhs.vars());
		Map<V, KBExp<C, V>> subst = (new THashMap<>());
		// Map<V, KBExp<C, V>> subst_inv = new THashMap<>();
		for (V v : vars) {
			V fr = fresh.next();
			subst.put(v, kb.factory.KBVar(fr));
			// subst_inv.put(fr, kb.factory.KBVar(v));
		}
		return new Pair<>(subst, null /* subst_inv */);
	}
 
Example #7
Source File: Frozen.java    From CQL with GNU Affero General Public License v3.0 6 votes vote down vote up
private Map<Pair<Var, Var>, Float> estimateSelectivities() {
	Map<Pair<Var, Var>, Float> ret = new THashMap<>();
	gens().keySet((v1) -> {
		gens().keySet((v2) -> {
			ret.put(new Pair<>(v1, v2), 1f);
		});
	});
	for (Pair<Term<Ty, En1, Sym, Fk1, Att1, Var, Var>, Term<Ty, En1, Sym, Fk1, Att1, Var, Var>> eq : eqs) {
		Set<Var> l = new THashSet<>();
		Set<Var> r = new THashSet<>();
		eq.first.gens(l);
		eq.second.gens(r);
		for (Var v : l) {
			for (Var u : r) {
				ret.put(new Pair<>(v, u), ret.get(new Pair<>(v, u)) * .5f);
				ret.put(new Pair<>(u, v), ret.get(new Pair<>(u, v)) * .5f);
			}
		}
	}
	return ret;
}
 
Example #8
Source File: SpellChecker.java    From CQL with GNU Affero General Public License v3.0 6 votes vote down vote up
private synchronized static Collection<String> getWords() {
	if (words0 != null) {
		return words0;
	}
	words0 = new THashSet<>();
	return words0;
	/*
	 * //SpellChecker.class.getR InputStream in =
	 * SpellChecker.class.getResourceAsStream("/words.txt"); if (in == null) {
	 * System.err.
	 * println("Warning: no words for spellchecker found.  If you are building from source, make sure words.txt is on the classpath."
	 * ); return words0; } try (BufferedReader reader = new BufferedReader(new
	 * InputStreamReader(in))) { String line; while ((line = reader.readLine()) !=
	 * null) { words0.add(line.toLowerCase().trim()); } } catch (IOException e1) {
	 * e1.printStackTrace(); } return words0;
	 */
}
 
Example #9
Source File: TransExpRaw.java    From CQL with GNU Affero General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
public TransExpRaw(InstExp<?, ?, ?, ?> src, InstExp<?, ?, ?, ?> dst, List<TransExp<?, ?, ?, ?, ?, ?, ?, ?>> imports,
		List<Pair<LocStr, RawTerm>> gens, List<Pair<String, String>> options) {
	this.src = (InstExp<Gen, Sk, String, String>) src;
	this.dst = (InstExp<Gen, Sk, String, String>) dst;
	this.imports = new THashSet<>(imports);
	this.gens = LocStr.set2(gens);
	Util.toMapSafely(this.gens); // do here rather than wait
	this.options = Util.toMapSafely(options);

	// List<InteriorLabel<Object>> t = InteriorLabel.imports("imports", imports);
	// raw.put("imports", t);

	List<InteriorLabel<Object>> f = new LinkedList<>();
	for (Pair<LocStr, RawTerm> p : gens) {
		f.add(new InteriorLabel<>("generators", new Pair<>(p.first.str, p.second), p.first.loc,
				x -> x.first + " -> " + x.second).conv());
	}
	raw.put("generators", f);
}
 
Example #10
Source File: SqlTable.java    From CQL with GNU Affero General Public License v3.0 6 votes vote down vote up
public void validate() {
	if (name == null) {
		throw new RuntimeException();
	}
	for (SqlColumn col : columns) {
		if (!col.table.equals(this)) {
			throw new RuntimeException();
		}
	}
	if (!columns.containsAll(pk)) {
		throw new RuntimeException();
	}
	if (columns.size() != new THashSet<>(columns).size()) {
		throw new RuntimeException();
	}
}
 
Example #11
Source File: LPOUKB.java    From CQL with GNU Affero General Public License v3.0 6 votes vote down vote up
private Set<Triple<KBExp<C, V>, KBExp<C, V>, Map<V, T>>> allcps(
		Set<Pair<Triple<KBExp<C, V>, KBExp<C, V>, Map<V, T>>, Triple<KBExp<C, V>, KBExp<C, V>, Map<V, T>>>> seen,
		Triple<KBExp<C, V>, KBExp<C, V>, Map<V, T>> ab) {
	Set<Triple<KBExp<C, V>, KBExp<C, V>, Map<V, T>>> ret = new THashSet<>();
	for (Triple<KBExp<C, V>, KBExp<C, V>, Map<V, T>> gd : R) {
		checkParentDead();
		Set<Triple<KBExp<C, V>, KBExp<C, V>, Map<V, T>>> s;
		if (!seen.contains(new Pair<>(ab, gd))) {
			s = cp(ab, gd);
			ret.addAll(s);
			seen.add(new Pair<>(ab, gd));
		}

		if (!seen.contains(new Pair<>(gd, ab))) {
			s = cp(gd, ab);
			ret.addAll(s);
			seen.add(new Pair<>(gd, ab));
		}
	}
	return ret;
}
 
Example #12
Source File: RedundantInferences.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Remove the redundant and marked as inferred super class assertions for
 * each class in the ontology signature. Uses the reasoner to infer the
 * direct super classes.
 * 
 * @param ontology
 * @param reasoner
 * @return map of class to set of redundant axioms
 */
public static Map<OWLClass, Set<RedundantAxiom>> removeRedundantSubClassAxioms(OWLOntology ontology, OWLReasoner reasoner) {
	Iterable<OWLClass> classes = ontology.getClassesInSignature();
	Map<OWLClass, Set<RedundantAxiom>> axioms = findRedundantSubClassAxioms(classes, ontology, reasoner);
	if (!axioms.isEmpty()) {
		Set<OWLSubClassOfAxiom> allAxioms = new THashSet<OWLSubClassOfAxiom>();
		for(OWLClass cls : axioms.keySet()) {
			for(RedundantAxiom redundantAxiom : axioms.get(cls)) {
				allAxioms.add(redundantAxiom.getAxiom());
			}
		}
		OWLOntologyManager manager = ontology.getOWLOntologyManager();
		manager.removeAxioms(ontology, allAxioms);
		LOG.info("Removed "+axioms.size()+" redundant axioms.");
	}
	return axioms;
	
}
 
Example #13
Source File: SchExpRaw.java    From CQL with GNU Affero General Public License v3.0 6 votes vote down vote up
public SchExpRaw(TyExp typeSide, List<SchExp> imports, List<LocStr> ens,
			List<Pair<LocStr, Pair<String, String>>> fks, List<Pair<Integer, Pair<List<String>, List<String>>>> list,
			List<Pair<LocStr, Pair<String, String>>> atts,
			List<Pair<Integer, Quad<String, String, RawTerm, RawTerm>>> list2, List<Pair<String, String>> options) {
		this.typeSide = typeSide;
		this.imports = new THashSet<>(imports);
		this.ens = LocStr.set1(ens);
		this.fks = LocStr.set2(fks);
		this.p_eqs = LocStr.proj2(list);
		this.atts = LocStr.set2(atts);
		this.t_eqs = LocStr.proj2(list2);
		this.options = Util.toMapSafely(options);
		
		if (this.fks.size() != fks.size()) {
			throw new RuntimeException("Error: schema literal contains duplicate foreign keys.");
		}
		if (this.atts.size() != atts.size()) {
			throw new RuntimeException("Error: schema literal contains duplicate attributes.");
		}
	
//		Util.toMapSafely(fks); // check no dups here rather than wait until eval
//		Util.toMapSafely(atts);

		doGuiIndexing(ens, fks, list, atts, list2);

	}
 
Example #14
Source File: KindCtx.java    From CQL with GNU Affero General Public License v3.0 6 votes vote down vote up
public Set<V> keySet() {
	Set<V> ret = new THashSet<>();
	ret.addAll(insts.keySet());
	ret.addAll(maps.keySet());
	ret.addAll(ps.keySet());
	ret.addAll(qs.keySet());
	ret.addAll(schs.keySet());
	ret.addAll(trans.keySet());
	ret.addAll(tys.keySet());
	ret.addAll(qs.keySet());
	ret.addAll(gs.keySet());
	ret.addAll(cs.keySet());
	ret.addAll(scs.keySet());
	ret.addAll(eds.keySet());
	ret.addAll(apgts.keySet());
	ret.addAll(apgis.keySet());
	ret.addAll(apgms.keySet());
	ret.addAll(apgschemas.keySet());
	ret.addAll(apgmappings.keySet());
	return ret;
}
 
Example #15
Source File: PartitionEquivalences.java    From metanome-algorithms with Apache License 2.0 6 votes vote down vote up
public void addPartition(EquivalenceManagedPartition partition) {
	if (!this.observedPartitions.contains(partition.getIndices()) && !this.containsSimilarPartition(partition)) {
		this.observedPartitions.add(partition.getIndices());
		long hashNumber = partition.getHashNumber();
		System.out.println(String.format("Partition[%s]\t%d\tSize: %d", partition.getIndices(), Long.valueOf(hashNumber), Integer.valueOf(partition.size())));
		partitionHashes.putIfAbsent(hashNumber, new TIntObjectHashMap<THashSet<EquivalenceManagedPartition>>());
		partitionHashes.get(hashNumber).putIfAbsent(partition.size(), new THashSet<EquivalenceManagedPartition>());
		THashSet<EquivalenceManagedPartition> partitionGroup = partitionHashes.get(hashNumber).get(partition.size());

		if (partitionGroup.isEmpty()) {
			partitionGroup.add(partition);
		} else {
			// then there is at least one element in the partitionGroup
			checkPossibleEquivalences(partitionGroup, partition);
		}
	}
}
 
Example #16
Source File: Observations.java    From metanome-algorithms with Apache License 2.0 5 votes vote down vote up
public THashSet<ColumnCollection> getUncheckedOrCandidateMinimalSupersets(ColumnCollection lhs, int rhsIndex, ColumnOrder order) {
	THashSet<ColumnCollection> uncheckedMinimalSupersets = new THashSet<>();
	
	for (int columnIndex : order.getOrderLowDistinctCount(lhs.setCopy(rhsIndex).complement())) {
		ColumnCollection supersetIndices = lhs.setCopy(columnIndex);
		if (!this.containsKey(supersetIndices) || this.get(supersetIndices) == Observation.CANDIDATE_MAXIMAL_NON_DEPENDENCY) {
			uncheckedMinimalSupersets.add(supersetIndices);
		}
	}
	return uncheckedMinimalSupersets;
}
 
Example #17
Source File: QueryExpRaw.java    From CQL with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public Collection<Pair<String, Kind>> deps() {
	Collection<Pair<String, Kind>> ret = new THashSet<>(src.deps());
	ret.addAll(dst.deps());
	for (QueryExp x : imports) {
		ret.addAll(x.deps());
	}
	return ret;
}
 
Example #18
Source File: SubMapping.java    From scheduler with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public Set<VM> getAllVMs() {
    if (all == null) {
        all = new THashSet<>();
        for (Node n : scope) {
            all.addAll(parent.getRunningVMs(n));
            all.addAll(parent.getSleepingVMs(n));
        }
        all.addAll(ready);
    }
    return all;
}
 
Example #19
Source File: TypingInversion.java    From CQL with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public ColimSchExpVar visitColimSchExpVar(Unit params, AqlTyping exp) throws RuntimeException {
	exp.defs.tys.put("t", Unit.unit);
	TyExpVar t = new TyExpVar("t");
	ColimSchExpVar x = new ColimSchExpVar("sc");
	exp.defs.scs.put("sc", new THashSet());
	ColimSchExpQuotient q = new ColimSchExpQuotient(t, Collections.emptyList(), Collections.emptyList(),
			Collections.emptyList(), Collections.emptyList(), Collections.emptyList());
	exp.prog.exps.put("sc", q);
	return x;
}
 
Example #20
Source File: TypingInversion.java    From CQL with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public MapExpColim visitMapExpColim(Unit params, AqlTyping exp) throws RuntimeException {
	exp.defs.tys.put("t", Unit.unit);
	TyExpVar t = new TyExpVar("t");
	exp.defs.scs.put("sc", new THashSet());
	exp.defs.schs.put("s", t);
	ColimSchExpQuotient q = new ColimSchExpQuotient(t, Collections.singletonList(new LocStr(0, "s")),
			Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), Collections.emptyList());
	exp.prog.exps.put("sc", q);
	return new MapExpColim("s", q);
}
 
Example #21
Source File: Chc.java    From CQL with GNU Affero General Public License v3.0 5 votes vote down vote up
public static <X, Y> Set<X> projIfAllLeft(Set<Chc<X, Y>> set) {
	Set<X> ret = new THashSet<>();

	for (Chc<X, Y> x : set) {
		if (x.left) {
			ret.add(x.l);
		} else {
			throw new RuntimeException("Cannot projLeft " + x);
		}
	}

	return ret;
}
 
Example #22
Source File: ApgInstExp.java    From CQL with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public Collection<Pair<String, Kind>> deps() {
	Set<Pair<String, Kind>> ret = new THashSet<>();
	for (ApgInstExp x : imports) {
		ret.addAll(x.deps());
	}
	ret.addAll(typeside.deps());
	return ret;
}
 
Example #23
Source File: UnionFind.java    From CQL with GNU Affero General Public License v3.0 5 votes vote down vote up
private synchronized Set<X> eqc(X x) {
	Set<X> ret = new THashSet<>();
	for (X x0 : iso2.keySet()) {
		if (connected(x, x0)) {
			ret.add(x0);
		}
	}
	return ret;
}
 
Example #24
Source File: Util.java    From CQL with GNU Affero General Public License v3.0 5 votes vote down vote up
public static <T> void assertNoDups(Collection<T> list) {

		Set<T> duplicates = new THashSet<>(list.size());
		Set<T> uniques = new THashSet<>(list.size());

		for (T t : list) {
			if (!uniques.add(t)) {
				duplicates.add(t);
			}
		}

		if (!duplicates.isEmpty()) {
			throw new RuntimeException("List contains duplicates, namely " + duplicates);
		}
	}
 
Example #25
Source File: ColimSchExp.java    From CQL with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public Set<Pair<SchExp, SchExp>> gotos(ColimSchExp ths) {
	Set<Pair<SchExp, SchExp>> ret = new THashSet<>();
	SchExp t = new SchExpColim(ths);
	for (SchExp s : nodes.values()) {
		ret.add(new Pair<>(s, t));
	}
	return ret;
}
 
Example #26
Source File: Observations.java    From metanome-algorithms with Apache License 2.0 5 votes vote down vote up
public THashSet<ColumnCollection> getUncheckedMinimalSupersets(ColumnCollection lhs, int rhsIndex, ColumnOrder order) {
	THashSet<ColumnCollection> uncheckedMinimalSupersets = new THashSet<>();
	
	for (int columnIndex : order.getOrderLowDistinctCount(lhs.setCopy(rhsIndex).complement())) {
		ColumnCollection supersetIndices = lhs.setCopy(columnIndex);
		if (!this.containsKey(supersetIndices)) {
			uncheckedMinimalSupersets.add(supersetIndices);
		}
	}
	return uncheckedMinimalSupersets;
}
 
Example #27
Source File: ColimSchExp.java    From CQL with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public Set<Pair<SchExp, SchExp>> gotos(ColimSchExp ths) {
	Set<Pair<SchExp, SchExp>> ret = new THashSet<>(nodes.size());
	SchExp t = new SchExpColim(ths);
	for (SchExp s : nodes.values()) {
		ret.add(new Pair<>(s, t));
	}
	return ret;
}
 
Example #28
Source File: ColimSchExp.java    From CQL with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public Collection<Pair<String, Kind>> deps() {
	Set<Pair<String, Kind>> ret = new THashSet<>();
	ret.addAll(ty.deps());
	for (SchExp v : nodes.values()) {
		ret.addAll(v.deps());
	}
	return ret;
}
 
Example #29
Source File: ColimSchExp.java    From CQL with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public synchronized ColimitSchema<String> eval0(AqlEnv env, boolean isC) {
	Map<String, Schema<Ty, En, Sym, Fk, Att>> nodes0 = new THashMap<>();
	Set<En> ens = new THashSet<>(nodes.size());
	for (String n : nodes.keySet()) {
		nodes0.put(n, nodes.get(n).eval(env, isC));
		ens.addAll(nodes0.get(n).ens.stream().map(x -> En.En(n + "_" + x)).collect(Collectors.toSet()));
	}

	return new ColimitSchema<>(nodes.keySet(), ty.eval(env, isC), nodes0, eqEn, eqTerms, eqTerms2,
			new AqlOptions(options, env.defaults));
}
 
Example #30
Source File: MyCollection.java    From fnlp with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static int getLength(THashSet<String> set) {
	int i = 0;
	TObjectHashIterator<String> it = set.iterator();
	while(it.hasNext()){
		String s = it.next();
		if(s.length()>i)
			i=s.length();
	}
	return i;
}