TriplePatternExtractor extends ElementVisitorBase { public Map<Var, Set<Triple>> extractTriplePatternsForProjectionVars(final Query query) { Map<Var, Set<Triple>> var2TriplePatterns = new HashMap<>(); for (Var var : query.getProjectVars()) { Set<Triple> triplePatterns = new HashSet<>(); triplePatterns.addAll(extractIngoingTriplePatterns(query, var)); triplePatterns.addAll(extractOutgoingTriplePatterns(query, var)); var2TriplePatterns.put(var, triplePatterns); } return var2TriplePatterns; }  Set<Triple> extractOutgoingTriplePatterns(final Query query, final Node node); Set<Triple> extractIngoingTriplePatterns(final Query query, final Node node); Set<Triple> extractTriplePatterns(final Query query, final Node node); Set<Triple> extractNonOptionalTriplePatterns(final Query query, final Node node); Map<Var, Set<Triple>> extractTriplePatternsForProjectionVars(final Query query); Map<Var, Set<Triple>> extractOutgoingTriplePatternsForProjectionVars(final Query query); Set<Triple> getOptionalTriplePatterns(); Map<Var, Set<Triple>> extractIngoingTriplePatternsForProjectionVars(final Query query); Set<Triple> extractTriplePattern(final Query query); Set<Triple> extractTriplePattern(final Query query, final boolean ignoreOptionals); boolean isOptional(final Triple triple); Set<Triple> extractTriplePattern(final ElementGroup group); Set<Triple> extractTriplePattern(final ElementGroup group, final boolean ignoreOptionals); @Override void visit(final ElementGroup el); @Override void visit(final ElementOptional el); @Override void visit(final ElementTriplesBlock el); @Override void visit(final ElementPathBlock el); @Override void visit(final ElementUnion el); @Override void visit(final ElementFilter el); int getUnionCount(); int getOptionalCount(); int getFilterCount();  }
@Test public void extractProjectionVarsTest() { Query q = QueryFactory.create("prefix dbp: <http: + "?thumbnail dbp2:thumbnail ?x. ?y dbp2:thumbnail ?c}"); String realAnswer = "[?thumbnail @http: TriplePatternExtractor triplePatternExtractor = new TriplePatternExtractor(); Map<Var,Set<Triple>> answer = triplePatternExtractor.extractTriplePatternsForProjectionVars(q); Set<Triple> extractedTriple = answer.get(q.getProjectVars().get(0)); Assert.assertTrue(realAnswer.equals(extractedTriple.toString())); }