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());
}
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());
}
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());
}
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());
}
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);
}
Aggregations