ConstructConsequentVisitor extends AbstractQueryModelVisitor<RuntimeException> { public Set<StatementPattern> getConsequents() { return consequentStatementPatterns; }  Set<StatementPattern> getConsequents(); Set<StatementPattern> getBnodes(); @Override void meet(Projection projection); @Override void meet(MultiProjection projection);  }
@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()); }
@Test public void testConcreteSP() { Extension extension = new Extension(new SingletonSet(), new ExtensionElem(new ValueConstant(FOAF.PERSON), "x"), new ExtensionElem(new ValueConstant(RDF.TYPE), "y"), new ExtensionElem(new ValueConstant(OWL.CLASS), "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(FOAF.PERSON), p(RDF.TYPE), o(OWL.CLASS))); Assert.assertEquals(expected, visitor.getConsequents()); }
@Test public void testMissingVariables() { Extension extension = new Extension(new SingletonSet(), new ExtensionElem(new ValueConstant(FOAF.PERSON), "x"), new ExtensionElem(new ValueConstant(RDF.TYPE), "y")); Projection projection = new Projection(extension, new ProjectionElemList( new ProjectionElem("x", "s"), 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(RDF.TYPE), o(null))); Assert.assertEquals(expected, visitor.getConsequents()); }
@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()); }
@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()); }
@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()); }