Search in sources :

Example 16 with ProjectionElemList

use of org.openrdf.query.algebra.ProjectionElemList in project incubator-rya by apache.

the class ConstructConsequentVisitorTest method testNoExtension.

@Test
public void testNoExtension() {
    StatementPattern sp = new StatementPattern(new Var("x"), new Var("y"), new Var("z"));
    Projection projection = new Projection(sp, new ProjectionElemList(new ProjectionElem("x", "subject"), new ProjectionElem("y", "predicate"), new ProjectionElem("z", "object")));
    ConstructConsequentVisitor visitor = new ConstructConsequentVisitor();
    projection.visit(visitor);
    Set<StatementPattern> expected = Sets.newHashSet(new StatementPattern(s(null), p(null), o(null)));
    Assert.assertEquals(expected, visitor.getConsequents());
}
Also used : ProjectionElemList(org.openrdf.query.algebra.ProjectionElemList) StatementPattern(org.openrdf.query.algebra.StatementPattern) Var(org.openrdf.query.algebra.Var) MultiProjection(org.openrdf.query.algebra.MultiProjection) Projection(org.openrdf.query.algebra.Projection) ProjectionElem(org.openrdf.query.algebra.ProjectionElem) Test(org.junit.Test)

Example 17 with ProjectionElemList

use of org.openrdf.query.algebra.ProjectionElemList in project incubator-rya by apache.

the class ConstructConsequentVisitorTest method testBNode.

@Test
public void testBNode() {
    Extension extension = new Extension(new SingletonSet(), new ExtensionElem(new Var("x"), "x"), new ExtensionElem(new BNodeGenerator(), "z"));
    Projection projection = new Projection(extension, new ProjectionElemList(new ProjectionElem("x", "subject"), new ProjectionElem("y", "predicate"), new ProjectionElem("z", "object")));
    ConstructConsequentVisitor visitor = new ConstructConsequentVisitor();
    projection.visit(visitor);
    Set<StatementPattern> expected = Sets.newHashSet(new StatementPattern(s(null), p(null), anon(o(null))));
    Assert.assertEquals(expected, visitor.getConsequents());
}
Also used : Extension(org.openrdf.query.algebra.Extension) ProjectionElemList(org.openrdf.query.algebra.ProjectionElemList) StatementPattern(org.openrdf.query.algebra.StatementPattern) BNodeGenerator(org.openrdf.query.algebra.BNodeGenerator) SingletonSet(org.openrdf.query.algebra.SingletonSet) Var(org.openrdf.query.algebra.Var) ExtensionElem(org.openrdf.query.algebra.ExtensionElem) MultiProjection(org.openrdf.query.algebra.MultiProjection) Projection(org.openrdf.query.algebra.Projection) ProjectionElem(org.openrdf.query.algebra.ProjectionElem) Test(org.junit.Test)

Example 18 with ProjectionElemList

use of org.openrdf.query.algebra.ProjectionElemList in project incubator-rya by apache.

the class ConstructConsequentVisitorTest method testGenericSP.

@Test
public void testGenericSP() {
    Extension extension = new Extension(new SingletonSet(), new ExtensionElem(new Var("z"), "z"));
    Projection projection = new Projection(extension, new ProjectionElemList(new ProjectionElem("x", "subject"), new ProjectionElem("y", "predicate"), new ProjectionElem("z", "object")));
    ConstructConsequentVisitor visitor = new ConstructConsequentVisitor();
    projection.visit(visitor);
    Set<StatementPattern> expected = Sets.newHashSet(new StatementPattern(s(null), p(null), o(null)));
    Assert.assertEquals(expected, visitor.getConsequents());
}
Also used : Extension(org.openrdf.query.algebra.Extension) ProjectionElemList(org.openrdf.query.algebra.ProjectionElemList) StatementPattern(org.openrdf.query.algebra.StatementPattern) SingletonSet(org.openrdf.query.algebra.SingletonSet) Var(org.openrdf.query.algebra.Var) ExtensionElem(org.openrdf.query.algebra.ExtensionElem) MultiProjection(org.openrdf.query.algebra.MultiProjection) Projection(org.openrdf.query.algebra.Projection) ProjectionElem(org.openrdf.query.algebra.ProjectionElem) Test(org.junit.Test)

Example 19 with ProjectionElemList

use of org.openrdf.query.algebra.ProjectionElemList in project incubator-rya by apache.

the class ConstructConsequentVisitorTest method testMultiProjection.

@Test
public void testMultiProjection() {
    Extension extension = new Extension(new SingletonSet(), new ExtensionElem(new ValueConstant(RDF.TYPE), "rdftype"), new ExtensionElem(new ValueConstant(OWL.OBJECTPROPERTY), "owlprop"), new ExtensionElem(new ValueConstant(OWL.EQUIVALENTCLASS), "owleqcls"), new ExtensionElem(new ValueConstant(OWL.CLASS), "owlclass"));
    MultiProjection projection = new MultiProjection(extension, Arrays.asList(new ProjectionElemList(new ProjectionElem("cls", "subject"), new ProjectionElem("rdftype", "predicate"), new ProjectionElem("owlclass", "object")), new ProjectionElemList(new ProjectionElem("prop", "subject"), new ProjectionElem("rdftype", "predicate"), new ProjectionElem("owlprop", "object")), new ProjectionElemList(new ProjectionElem("owleqcls", "predicate"), new ProjectionElem("cls", "object"))));
    ConstructConsequentVisitor visitor = new ConstructConsequentVisitor();
    projection.visit(visitor);
    Set<StatementPattern> expected = Sets.newHashSet(new StatementPattern(s(null), p(RDF.TYPE), o(OWL.CLASS)), new StatementPattern(s(null), p(RDF.TYPE), o(OWL.OBJECTPROPERTY)), new StatementPattern(s(null), p(OWL.EQUIVALENTCLASS), o(null)));
    Assert.assertEquals(expected, visitor.getConsequents());
}
Also used : Extension(org.openrdf.query.algebra.Extension) ProjectionElemList(org.openrdf.query.algebra.ProjectionElemList) StatementPattern(org.openrdf.query.algebra.StatementPattern) SingletonSet(org.openrdf.query.algebra.SingletonSet) ValueConstant(org.openrdf.query.algebra.ValueConstant) ExtensionElem(org.openrdf.query.algebra.ExtensionElem) MultiProjection(org.openrdf.query.algebra.MultiProjection) ProjectionElem(org.openrdf.query.algebra.ProjectionElem) Test(org.junit.Test)

Example 20 with ProjectionElemList

use of org.openrdf.query.algebra.ProjectionElemList in project incubator-rya by apache.

the class AggregationPipelineQueryNodeTest method testProject.

@Test
public void testProject() {
    final AggregationPipelineQueryNode base = new AggregationPipelineQueryNode(collection, new LinkedList<>(), Sets.newHashSet("x", "y"), Sets.newHashSet("x", "y", "opt"), HashBiMap.create());
    // Add a single projection
    ProjectionElemList singleProjection = new ProjectionElemList();
    singleProjection.addElement(new ProjectionElem("x", "z"));
    singleProjection.addElement(new ProjectionElem("y", "y"));
    List<ProjectionElemList> projections = Arrays.asList(singleProjection);
    AggregationPipelineQueryNode node = base.clone();
    boolean success = node.project(projections);
    Assert.assertTrue(success);
    Assert.assertEquals(1, node.getPipeline().size());
    Assert.assertEquals(Sets.newHashSet("z", "y"), node.getAssuredBindingNames());
    Assert.assertEquals(Sets.newHashSet("z", "y"), node.getBindingNames());
    // Add a multi-projection
    ProjectionElemList p1 = new ProjectionElemList();
    p1.addElement(new ProjectionElem("x", "solution"));
    ProjectionElemList p2 = new ProjectionElemList();
    p2.addElement(new ProjectionElem("y", "solution"));
    ProjectionElemList p3 = new ProjectionElemList();
    p3.addElement(new ProjectionElem("x", "x"));
    p3.addElement(new ProjectionElem("x", "solution"));
    p3.addElement(new ProjectionElem("y", "y"));
    projections = Arrays.asList(p1, p2, p3);
    node = base.clone();
    success = node.project(projections);
    Assert.assertTrue(success);
    Assert.assertEquals(3, node.getPipeline().size());
    Assert.assertEquals(Sets.newHashSet("solution"), node.getAssuredBindingNames());
    Assert.assertEquals(Sets.newHashSet("x", "y", "solution"), node.getBindingNames());
    // Add no projections
    node = base.clone();
    success = node.project(Arrays.asList());
    Assert.assertFalse(success);
    Assert.assertEquals(base, node);
}
Also used : ProjectionElemList(org.openrdf.query.algebra.ProjectionElemList) ProjectionElem(org.openrdf.query.algebra.ProjectionElem) Test(org.junit.Test)

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