List of usage examples for org.apache.commons.collections15 MultiMap keySet
Set<K> keySet();
From source file:de.dhke.projects.cutil.collections.MultiMapUtil.java
public static <K, V> boolean deepEquals(MultiMap<K, V> m1, MultiMap<? extends K, ? extends V> m2) { for (Map.Entry<K, Collection<V>> entry1 : m1.entrySet()) { if (!m2.containsKey(entry1.getKey())) return false; else {// w w w.j a v a 2s .c o m final Collection<? extends V> values2 = m2.get(entry1.getKey()); if ((!entry1.getValue().containsAll(values2)) || (!values2.containsAll(entry1.getValue()))) return false; } } return m1.keySet().containsAll(m2.keySet()); }
From source file:org.aksw.resparql.ServerMethods.java
public Model getAreaStatistics(RectangularShape shape, List<String> classUris) throws Exception { Model result = ModelFactory.createDefaultModel(); classUris = new ArrayList<String>(); classUris.add("http://linkedgeodata.org/ontology/Amenity"); classUris.add("http://linkedgeodata.org/ontology/Tourism"); classUris.add("http://linkedgeodata.org/ontology/Leisure"); classUris.add("http://linkedgeodata.org/ontology/Shop"); Map<String, Set<Tag>> classToTags = new HashMap<String, Set<Tag>>(); // Reverse map all classUris OntologyDAO dao = lgdRDFDAO.getOntologyDAO(); for (String uri : classUris) { Set<Tag> tags = MultiMaps.addKey(classToTags, uri); MultiMap<Tag, IOneOneTagMapper> rev = dao.reverseMapResourceObject(RDF.type.getURI(), uri); for (Tag tag : rev.keySet()) { if (tag.getKey() == null) { tags.clear();// w w w . java 2 s . c om tags.add(tag); } else if (tag.getValue() == null) { for (Iterator<Tag> it = tags.iterator(); it.hasNext();) { if (it.next().getKey().equals(tag.getKey())) { it.remove(); } } tags.add(tag); } else { boolean isSubsumed = false; for (Tag tmp : tags) { if (tmp.getKey() == null || tmp.getValue() == null) { isSubsumed = true; break; } } if (!isSubsumed) { tags.add(tag); } } } } Set<String> keys = new HashSet<String>(); //Set<Tag> tags = new HashSet<Tag>(); for (Set<Tag> tags : classToTags.values()) { for (Tag tag : tags) { if (tag.getValue() == null) { keys.add(tag.getKey()); } } } Connection conn = lgdRDFDAO.getConnection(); String sql = LGDQueries.buildAreaStatsQueryExact(shape, keys); java.sql.ResultSet rs = conn.createStatement().executeQuery(sql); Map<String, Long> keyToCount = new HashMap<String, Long>(); while (rs.next()) { keyToCount.put(rs.getString("k"), rs.getLong("c")); } //for( Map<String, Long> uriToCount = new HashMap<String, Long>(); // Cross check the tags with the requested classes return result; }
From source file:org.openanzo.glitter.query.SPARQLAlgebra.java
/** * Evaluates and binds the expressions in the given assignments to the corresponding variables. * /* w w w .j a v a 2 s . c om*/ * @param answers * @param assignments * @return SolutionSet with assignments assigned * @throws ExpressionEvaluationException */ static public SolutionSet processAssignments(SolutionSet answers, MultiMap<Variable, Expression> assignments) throws ExpressionEvaluationException { SolutionList newAnswers = new SolutionList(); ListIterator<PatternSolution> it = answers.listIterator(); while (it.hasNext()) { // TODO there are evaluation optimizations here if the LET expressions don't depend on variables in // the answers _and_ if the expressions are pure functional (no side effects/outside state involved) PatternSolution solution = it.next(); PatternSolutionImpl newSolution = new PatternSolutionImpl(solution); boolean keepSolution = true; for (Variable v : assignments.keySet()) { for (Expression e : assignments.get(v)) { // allow aggregates to operate over the given solutions // evaluate in the context of the solution going in, but compare with the new solution // we're building up (extending the original solution) Value assignedVal = e.evaluate(solution, answers); if (assignedVal == null) continue; Value currentVal = newSolution.getBinding(v); if (currentVal != null && !currentVal.equals(assignedVal)) { // joining this assignment to this solution results fails, so the solution // is removed from the results keepSolution = false; break; } else if (currentVal == null) { newSolution.setBinding(v, assignedVal); } } if (!keepSolution) break; } if (keepSolution) newAnswers.add(newSolution); } return newAnswers; }