@Test public void testMultipleQueriesInterpretation() throws Exception { StringBuilder buffer = new StringBuilder(); buffer.append("SELECT sub1, score1, snippet1, sub2, score2, snippet2, x, p1, p2 "); buffer.append("FROM {sub1} <" + MATCHES + "> {} "); buffer.append("<" + TYPE + "> {<" + LUCENE_QUERY + ">}; "); buffer.append("<" + QUERY + "> {\"my Lucene query\"}; "); buffer.append("<" + SCORE + "> {score1}; "); buffer.append("<" + SNIPPET + "> {snippet1}, "); buffer.append("{sub2} <" + MATCHES + "> {} "); buffer.append("<" + TYPE + "> {<" + LUCENE_QUERY + ">}; "); buffer.append("<" + QUERY + "> {\"second lucene query\"}; "); buffer.append("<" + SCORE + "> {score2}; "); buffer.append("<" + SNIPPET + "> {snippet2}, "); buffer.append("{sub1} p1 {x}, {x} p2 {sub2} "); ParsedQuery query = parser.parseQuery(buffer.toString(), null); TupleExpr tupleExpr = query.getTupleExpr(); Collection<SearchQueryEvaluator> queries = process(interpreter, tupleExpr); assertEquals(2, queries.size()); Iterator<SearchQueryEvaluator> i = queries.iterator(); boolean matched1 = false; boolean matched2 = false; while (i.hasNext()) { QuerySpec querySpec = (QuerySpec) i.next(); if ("sub1".equals(querySpec.getMatchesVariableName())) { assertEquals("sub1", querySpec.getMatchesPattern().getSubjectVar().getName()); assertEquals("my Lucene query", ((Literal) querySpec.getQueryPattern().getObjectVar().getValue()).getLabel()); assertEquals("score1", querySpec.getScorePattern().getObjectVar().getName()); assertEquals("snippet1", querySpec.getSnippetPattern().getObjectVar().getName()); assertEquals(LUCENE_QUERY, querySpec.getTypePattern().getObjectVar().getValue()); assertEquals("my Lucene query", querySpec.getQueryString()); assertNull(querySpec.getSubject()); matched1 = true; } else if ("sub2".equals(querySpec.getMatchesVariableName())) { assertEquals("sub2", querySpec.getMatchesPattern().getSubjectVar().getName()); assertEquals("second lucene query", ((Literal) querySpec.getQueryPattern().getObjectVar().getValue()).getLabel()); assertEquals("score2", querySpec.getScorePattern().getObjectVar().getName()); assertEquals("snippet2", querySpec.getSnippetPattern().getObjectVar().getName()); assertEquals(LUCENE_QUERY, querySpec.getTypePattern().getObjectVar().getValue()); assertEquals("second lucene query", querySpec.getQueryString()); assertNull(querySpec.getSubject()); matched2 = true; } else fail("Found unexpected query spec: " + querySpec.toString()); } if (!matched1) fail("did not find query patter sub1"); if (!matched2) fail("did not find query patter sub2"); }
@SuppressWarnings("unchecked") @Deprecated public Set<QuerySpec> process(TupleExpr tupleExpr, BindingSet bindings) throws SailException { HashSet<QuerySpec> result = new HashSet<>(); process(tupleExpr, bindings, (Collection<SearchQueryEvaluator>) (Collection<?>) result); return result; }
QuerySpecBuilder implements SearchQueryInterpreter { @SuppressWarnings("unchecked") @Deprecated public Set<QuerySpec> process(TupleExpr tupleExpr, BindingSet bindings) throws SailException { HashSet<QuerySpec> result = new HashSet<>(); process(tupleExpr, bindings, (Collection<SearchQueryEvaluator>) (Collection<?>) result); return result; } }
QuerySpecBuilder implements SearchQueryInterpreter { @SuppressWarnings("unchecked") @Deprecated public Set<QuerySpec> process(TupleExpr tupleExpr, BindingSet bindings) throws SailException { HashSet<QuerySpec> result = new HashSet<>(); process(tupleExpr, bindings, (Collection<SearchQueryEvaluator>) (Collection<?>) result); return result; } QuerySpecBuilder(boolean incompleteQueryFails); }
QuerySpecBuilder implements SearchQueryInterpreter { @SuppressWarnings("unchecked") @Deprecated public Set<QuerySpec> process(TupleExpr tupleExpr, BindingSet bindings) throws SailException { HashSet<QuerySpec> result = new HashSet<>(); process(tupleExpr, bindings, (Collection<SearchQueryEvaluator>) (Collection<?>) result); return result; } QuerySpecBuilder(boolean incompleteQueryFails); @SuppressWarnings("unchecked") @Deprecated Set<QuerySpec> process(TupleExpr tupleExpr, BindingSet bindings); @Override void process(TupleExpr tupleExpr, BindingSet bindings, Collection<SearchQueryEvaluator> result); }
QuerySpecBuilder implements SearchQueryInterpreter { @SuppressWarnings("unchecked") @Deprecated public Set<QuerySpec> process(TupleExpr tupleExpr, BindingSet bindings) throws SailException { HashSet<QuerySpec> result = new HashSet<>(); process(tupleExpr, bindings, (Collection<SearchQueryEvaluator>) (Collection<?>) result); return result; } QuerySpecBuilder(boolean incompleteQueryFails); @SuppressWarnings("unchecked") @Deprecated Set<QuerySpec> process(TupleExpr tupleExpr, BindingSet bindings); @Override void process(TupleExpr tupleExpr, BindingSet bindings, Collection<SearchQueryEvaluator> result);  }