Search in sources :

Example 26 with ProjectionElemList

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);
}
Also used : ProjectionElemList(org.openrdf.query.algebra.ProjectionElemList) StatementPattern(org.openrdf.query.algebra.StatementPattern) Var(org.openrdf.query.algebra.Var) Projection(org.openrdf.query.algebra.Projection) RdfCloudTripleStoreConfiguration(org.apache.rya.api.RdfCloudTripleStoreConfiguration) ProjectionElem(org.openrdf.query.algebra.ProjectionElem) Test(org.junit.Test)

Example 27 with ProjectionElemList

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);
}
Also used : ProjectionElemList(org.openrdf.query.algebra.ProjectionElemList) FixedStatementPattern(org.apache.rya.rdftriplestore.utils.FixedStatementPattern) StatementPattern(org.openrdf.query.algebra.StatementPattern) Set(java.util.Set) HashMap(java.util.HashMap) Var(org.openrdf.query.algebra.Var) Resource(org.openrdf.model.Resource) Projection(org.openrdf.query.algebra.Projection) AccumuloRdfConfiguration(org.apache.rya.accumulo.AccumuloRdfConfiguration) ProjectionElem(org.openrdf.query.algebra.ProjectionElem) Test(org.junit.Test)

Example 28 with ProjectionElemList

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());
}
Also used : ProjectionElemList(org.openrdf.query.algebra.ProjectionElemList) StatementPattern(org.openrdf.query.algebra.StatementPattern) QueryRoot(org.openrdf.query.algebra.QueryRoot) MultiProjection(org.openrdf.query.algebra.MultiProjection) Projection(org.openrdf.query.algebra.Projection) Test(org.junit.Test)

Example 29 with ProjectionElemList

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());
}
Also used : ProjectionElemList(org.openrdf.query.algebra.ProjectionElemList) StatementPattern(org.openrdf.query.algebra.StatementPattern) QueryRoot(org.openrdf.query.algebra.QueryRoot) Var(org.openrdf.query.algebra.Var) Join(org.openrdf.query.algebra.Join) MultiProjection(org.openrdf.query.algebra.MultiProjection) ProjectionElem(org.openrdf.query.algebra.ProjectionElem) Test(org.junit.Test)

Example 30 with ProjectionElemList

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;
}
Also used : ProjectionElemList(org.openrdf.query.algebra.ProjectionElemList) Var(org.openrdf.query.algebra.Var) Projection(org.openrdf.query.algebra.Projection) TupleQueryBuilder(edu.mit.simile.backstage.model.TupleQueryBuilder) ParsedTupleQuery(org.openrdf.query.parser.ParsedTupleQuery) MyTupleQuery(edu.mit.simile.backstage.util.MyTupleQuery) TupleQuery(org.openrdf.query.TupleQuery) MyTupleQuery(edu.mit.simile.backstage.util.MyTupleQuery) ProjectionElem(org.openrdf.query.algebra.ProjectionElem) TupleExpr(org.openrdf.query.algebra.TupleExpr) ParsedTupleQuery(org.openrdf.query.parser.ParsedTupleQuery)

Aggregations

ProjectionElemList (org.openrdf.query.algebra.ProjectionElemList)30 ProjectionElem (org.openrdf.query.algebra.ProjectionElem)26 Test (org.junit.Test)25 Projection (org.openrdf.query.algebra.Projection)24 StatementPattern (org.openrdf.query.algebra.StatementPattern)24 Var (org.openrdf.query.algebra.Var)21 MultiProjection (org.openrdf.query.algebra.MultiProjection)10 Union (org.openrdf.query.algebra.Union)10 HashSet (java.util.HashSet)9 Resource (org.openrdf.model.Resource)9 Extension (org.openrdf.query.algebra.Extension)9 ExtensionElem (org.openrdf.query.algebra.ExtensionElem)8 Join (org.openrdf.query.algebra.Join)8 TupleExpr (org.openrdf.query.algebra.TupleExpr)8 HashMap (java.util.HashMap)7 Set (java.util.Set)7 FixedStatementPattern (org.apache.rya.rdftriplestore.utils.FixedStatementPattern)6 SingletonSet (org.openrdf.query.algebra.SingletonSet)5 URI (org.openrdf.model.URI)4 AccumuloRdfConfiguration (org.apache.rya.accumulo.AccumuloRdfConfiguration)3