use of org.openrdf.query.algebra.ProjectionElemList in project incubator-rya by apache.
the class ReflexivePropertyVisitorTest method testReflexivePropertyDisabled.
@Test
public void testReflexivePropertyDisabled() throws Exception {
// Disable inference
final RdfCloudTripleStoreConfiguration disabledConf = conf.clone();
disabledConf.setInferReflexiveProperty(false);
// Define a reflexive property
final InferenceEngine inferenceEngine = mock(InferenceEngine.class);
when(inferenceEngine.isReflexiveProperty(HAS_FAMILY)).thenReturn(true);
// Construct a query, then make a copy and visit the copy
final Projection query = new Projection(new StatementPattern(new Var("s", ALICE), new Var("p", HAS_FAMILY), new Var("o")), new ProjectionElemList(new ProjectionElem("s", "subject")));
final Projection modifiedQuery = query.clone();
modifiedQuery.visit(new ReflexivePropertyVisitor(disabledConf, inferenceEngine));
// There should be no difference
Assert.assertEquals(query, modifiedQuery);
}
use of org.openrdf.query.algebra.ProjectionElemList in project incubator-rya by apache.
the class SomeValuesFromVisitorTest method testSomeValuesFromDisabled.
@Test
public void testSomeValuesFromDisabled() throws Exception {
// Disable someValuesOf inference
final AccumuloRdfConfiguration disabledConf = conf.clone();
disabledConf.setInferSomeValuesFrom(false);
// Configure a mock instance engine with an ontology:
final InferenceEngine inferenceEngine = mock(InferenceEngine.class);
Map<Resource, Set<URI>> personSVF = new HashMap<>();
personSVF.put(gradCourse, Sets.newHashSet(takesCourse));
personSVF.put(course, Sets.newHashSet(takesCourse));
personSVF.put(department, Sets.newHashSet(headOf));
personSVF.put(organization, Sets.newHashSet(worksFor, headOf));
when(inferenceEngine.getSomeValuesFromByRestrictionType(person)).thenReturn(personSVF);
// Query for a specific type visit -- should not change
StatementPattern originalSP = new StatementPattern(new Var("s"), new Var("p", RDF.TYPE), new Var("o", person));
final Projection originalQuery = new Projection(originalSP, new ProjectionElemList(new ProjectionElem("s", "subject")));
final Projection modifiedQuery = originalQuery.clone();
modifiedQuery.visit(new SomeValuesFromVisitor(disabledConf, inferenceEngine));
Assert.assertEquals(originalQuery, modifiedQuery);
}
use of org.openrdf.query.algebra.ProjectionElemList in project incubator-rya by apache.
the class SparqlToPipelineTransformVisitorTest method testEmptyProjection.
@Test
public void testEmptyProjection() throws Exception {
StatementPattern isClass = new StatementPattern(constant(UNDERGRAD), constant(RDF.TYPE), constant(OWL.CLASS));
QueryRoot queryTree = new QueryRoot(new Projection(isClass, new ProjectionElemList()));
SparqlToPipelineTransformVisitor visitor = new SparqlToPipelineTransformVisitor(collection);
queryTree.visit(visitor);
Assert.assertTrue(queryTree.getArg() instanceof Projection);
Projection projectNode = (Projection) queryTree.getArg();
Assert.assertTrue(projectNode.getArg() instanceof AggregationPipelineQueryNode);
AggregationPipelineQueryNode pipelineNode = (AggregationPipelineQueryNode) projectNode.getArg();
Assert.assertEquals(Sets.newHashSet(), pipelineNode.getAssuredBindingNames());
}
use of org.openrdf.query.algebra.ProjectionElemList in project incubator-rya by apache.
the class SparqlToPipelineTransformVisitorTest method testMultiProjection.
@Test
public void testMultiProjection() throws Exception {
StatementPattern isUndergrad = new StatementPattern(new Var("x"), constant(RDF.TYPE), constant(UNDERGRAD));
StatementPattern isCourse = new StatementPattern(new Var("course"), constant(RDF.TYPE), constant(COURSE));
StatementPattern hasEdge = new StatementPattern(new Var("x"), new Var("p"), new Var("course"));
ProjectionElemList courseHasRelation = new ProjectionElemList(new ProjectionElem("p", "relation"), new ProjectionElem("course"));
ProjectionElemList studentHasRelation = new ProjectionElemList(new ProjectionElem("p", "relation"), new ProjectionElem("x", "student"));
QueryRoot queryTree = new QueryRoot(new MultiProjection(new Join(new Join(isCourse, hasEdge), isUndergrad), Arrays.asList(courseHasRelation, studentHasRelation)));
SparqlToPipelineTransformVisitor visitor = new SparqlToPipelineTransformVisitor(collection);
queryTree.visit(visitor);
Assert.assertTrue(queryTree.getArg() instanceof AggregationPipelineQueryNode);
AggregationPipelineQueryNode pipelineNode = (AggregationPipelineQueryNode) queryTree.getArg();
Assert.assertEquals(Sets.newHashSet("relation"), pipelineNode.getAssuredBindingNames());
Assert.assertEquals(Sets.newHashSet("relation", "course", "student"), pipelineNode.getBindingNames());
}
use of org.openrdf.query.algebra.ProjectionElemList in project backstage by zepheira.
the class Expression method computeOutputOnValue.
public ExpressionQueryResult computeOutputOnValue(Value value, Database database, SailRepositoryConnection connection) throws ExpressionException {
TupleQueryBuilder builder = new TupleQueryBuilder();
Var valueVar = builder.makeVar("value", value);
ExpressionResult expressionResult = computeOutputOnItem(database, builder, valueVar);
if (expressionResult.valueExpr instanceof Var) {
Var resultVar = (Var) expressionResult.valueExpr;
ProjectionElemList projectionElements = new ProjectionElemList();
projectionElements.addElement(new ProjectionElem(resultVar.getName()));
TupleExpr t = builder.makeFilterTupleExpr();
if (t == null) {
// TODO[dfhuynh]: This happens if the expression is just "value". I'm not sure what to do here.
return null;
}
Projection projection = new Projection(t, projectionElements);
TupleQuery query = new MyTupleQuery(new ParsedTupleQuery(projection), connection);
return new ExpressionQueryResult(query, expressionResult.valueType, resultVar);
}
return null;
}
Aggregations