use of org.openrdf.query.algebra.helpers.StatementPatternCollector in project QueryAnalysis by Wikidata.
the class OpenRDFQueryHandler method computeTripleCountWithService.
/**
* {@inheritDoc}
*/
@Override
protected final void computeTripleCountWithService() {
if (getValidityStatus() != QueryHandler.Validity.VALID) {
this.tripleCountWithService = -1;
return;
}
TupleExpr expr = this.query.getTupleExpr();
StatementPatternCollector collector = new StatementPatternCollector();
expr.visit(collector);
this.tripleCountWithService = collector.getStatementPatterns().size();
}
use of org.openrdf.query.algebra.helpers.StatementPatternCollector in project QueryAnalysis by Wikidata.
the class OpenRDFQueryHandler method computeVariableCountPattern.
/**
* {@inheritDoc}
*/
@Override
protected final void computeVariableCountPattern() {
if (getValidityStatus() != QueryHandler.Validity.VALID) {
this.variableCountPattern = -1;
return;
}
final Set<Var> variables = new HashSet<>();
TupleExpr expr = this.query.getTupleExpr();
StatementPatternCollector collector = new StatementPatternCollector();
expr.visit(collector);
List<StatementPattern> statementPatterns = collector.getStatementPatterns();
for (StatementPattern statementPattern : statementPatterns) {
List<Var> statementVariables = statementPattern.getVarList();
for (Var statementVariable : statementVariables) {
if (!statementVariable.isConstant()) {
variables.add(statementVariable);
}
}
}
this.variableCountPattern = variables.size();
}
use of org.openrdf.query.algebra.helpers.StatementPatternCollector in project incubator-rya by apache.
the class MongoDbSmartUriIT method testStorage.
@Test
public void testStorage() throws SmartUriException, MalformedQueryException, RuntimeException, QueryEvaluationException {
smartUriConverter.storeEntity(BOB_ENTITY);
final String sparql = "SELECT * WHERE { " + "<" + BOB.getData() + "> <" + RDF.TYPE + "> <" + PERSON_TYPE.getId().getData() + "> . " + "<" + BOB.getData() + "> <" + HAS_SSN.getData() + "> ?ssn . " + "<" + BOB.getData() + "> <" + HAS_AGE.getData() + "> ?age . " + "<" + BOB.getData() + "> <" + HAS_WEIGHT.getData() + "> ?weight . " + "<" + BOB.getData() + "> <" + HAS_ADDRESS.getData() + "> ?address . " + "}";
final StatementPatternCollector spCollector = new StatementPatternCollector();
new SPARQLParser().parseQuery(sparql, null).getTupleExpr().visit(spCollector);
final List<StatementPattern> patterns = spCollector.getStatementPatterns();
final EntityQueryNode entityQueryNode = new EntityQueryNode(PERSON_TYPE, patterns, smartUriConverter.getEntityStorage());
final QueryBindingSet queryBindingSet = new QueryBindingSet();
final Property ssnProperty = BOB_ENTITY.lookupTypeProperty(PERSON_TYPE, HAS_SSN).get();
queryBindingSet.addBinding(HAS_SSN.getData(), RyaToRdfConversions.convertValue(ssnProperty.getValue()));
final CloseableIteration<BindingSet, QueryEvaluationException> iter = entityQueryNode.evaluate(queryBindingSet);
int count = 0;
// These should match what was used in the SPARQL query.
final List<String> queryParamNames = Lists.newArrayList("ssn", "age", "weight", "address");
while (iter.hasNext()) {
final BindingSet bs = iter.next();
assertTrue(bs.getBindingNames().containsAll(queryParamNames));
count++;
}
assertEquals(count, 1);
}
use of org.openrdf.query.algebra.helpers.StatementPatternCollector in project incubator-rya by apache.
the class GeoTemporalTestUtils method getSps.
public static List<StatementPattern> getSps(final String query) throws Exception {
final StatementPatternCollector collector = new StatementPatternCollector();
new SPARQLParser().parseQuery(query, null).getTupleExpr().visit(collector);
return collector.getStatementPatterns();
}
use of org.openrdf.query.algebra.helpers.StatementPatternCollector in project incubator-rya by apache.
the class GeneralizedExternalProcessor method getQNodes.
private static Set<QueryModelNode> getQNodes(QueryModelNode queryNode) {
Set<QueryModelNode> rtns = new HashSet<QueryModelNode>();
StatementPatternCollector spc = new StatementPatternCollector();
queryNode.visit(spc);
rtns.addAll(spc.getStatementPatterns());
FilterCollector fvis = new FilterCollector();
queryNode.visit(fvis);
rtns.addAll(fvis.getFilters());
ExternalTupleCollector eVis = new ExternalTupleCollector();
queryNode.visit(eVis);
rtns.addAll(eVis.getExtTup());
return rtns;
}
Aggregations