Search in sources :

Example 31 with ElementPathBlock

use of org.apache.jena.sparql.syntax.ElementPathBlock in project jena by apache.

the class WhereClauseTest method testAddOptionalTriplePath.

@ContractTest
public void testAddOptionalTriplePath() {
    WhereClause<?> whereClause = getProducer().newInstance();
    PrefixMapping pmap = new PrefixMappingImpl();
    pmap.setNsPrefix("ts", "urn:test:");
    Path path = PathParser.parse("ts:two/ts:dos", pmap);
    AbstractQueryBuilder<?> builder = whereClause.addOptional(new TriplePath(NodeFactory.createURI("one"), path, NodeFactory.createURI("three")));
    ElementPathBlock epb = new ElementPathBlock();
    ElementOptional optional = new ElementOptional(epb);
    TriplePath tp = new TriplePath(NodeFactory.createURI("one"), path, NodeFactory.createURI("three"));
    epb.addTriplePath(tp);
    WhereValidator visitor = new WhereValidator(optional);
    builder.build().getQueryPattern().visit(visitor);
    assertTrue(visitor.matching);
}
Also used : TriplePath(org.apache.jena.sparql.core.TriplePath) Path(org.apache.jena.sparql.path.Path) PrefixMapping(org.apache.jena.shared.PrefixMapping) ElementOptional(org.apache.jena.sparql.syntax.ElementOptional) WhereValidator(org.apache.jena.arq.querybuilder.WhereValidator) TriplePath(org.apache.jena.sparql.core.TriplePath) PrefixMappingImpl(org.apache.jena.shared.impl.PrefixMappingImpl) ElementPathBlock(org.apache.jena.sparql.syntax.ElementPathBlock) ContractTest(org.xenei.junit.contract.ContractTest)

Example 32 with ElementPathBlock

use of org.apache.jena.sparql.syntax.ElementPathBlock in project jena by apache.

the class WhereClauseTest method testSetVarsInTriple_Node_Variable.

@ContractTest
public void testSetVarsInTriple_Node_Variable() {
    Node v = NodeFactory.createVariable("v");
    Node one = NodeFactory.createURI("one");
    Node two = NodeFactory.createURI("two");
    Node three = NodeFactory.createURI("three");
    Node four = NodeFactory.createURI("four");
    WhereClause<?> whereClause = getProducer().newInstance();
    AbstractQueryBuilder<?> builder = whereClause.addWhere(new Triple(one, two, v));
    TriplePath tp = new TriplePath(new Triple(one, two, Var.alloc(v)));
    ElementPathBlock epb = new ElementPathBlock();
    epb.addTriple(tp);
    WhereValidator visitor = new WhereValidator(epb);
    builder.build().getQueryPattern().visit(visitor);
    assertTrue(visitor.matching);
    builder.setVar(v, three);
    tp = new TriplePath(new Triple(one, two, three));
    epb = new ElementPathBlock();
    epb.addTriple(tp);
    visitor = new WhereValidator(epb);
    builder.build().getQueryPattern().visit(visitor);
    assertTrue(visitor.matching);
    builder.setVar(v, four);
    tp = new TriplePath(new Triple(one, two, four));
    epb = new ElementPathBlock();
    epb.addTriple(tp);
    visitor = new WhereValidator(epb);
    builder.build().getQueryPattern().visit(visitor);
    assertTrue(visitor.matching);
    builder.setVar(v, null);
    tp = new TriplePath(new Triple(one, two, Var.alloc("v")));
    epb = new ElementPathBlock();
    epb.addTriple(tp);
    visitor = new WhereValidator(epb);
    builder.build().getQueryPattern().visit(visitor);
    assertTrue(visitor.matching);
}
Also used : Triple(org.apache.jena.graph.Triple) FrontsTriple(org.apache.jena.graph.FrontsTriple) WhereValidator(org.apache.jena.arq.querybuilder.WhereValidator) Node(org.apache.jena.graph.Node) TriplePath(org.apache.jena.sparql.core.TriplePath) ElementPathBlock(org.apache.jena.sparql.syntax.ElementPathBlock) ContractTest(org.xenei.junit.contract.ContractTest)

Example 33 with ElementPathBlock

use of org.apache.jena.sparql.syntax.ElementPathBlock in project jena by apache.

the class WhereClauseTest method testSetVarsInUnion_Node_Variable.

@ContractTest
public void testSetVarsInUnion_Node_Variable() {
    Node v = NodeFactory.createVariable("v");
    SelectBuilder sb1 = new SelectBuilder().addPrefix("pfx", "uri").addWhere("<one>", "<two>", v);
    WhereClause<?> whereClause = getProducer().newInstance();
    whereClause.addUnion(sb1);
    SelectBuilder sb2 = new SelectBuilder().addWhere("<uno>", "<dos>", "<tres>");
    AbstractQueryBuilder<?> builder = whereClause.addUnion(sb2);
    Query query = builder.build();
    Node one = NodeFactory.createURI("one");
    Node two = NodeFactory.createURI("two");
    Node three = NodeFactory.createURI("three");
    Node uno = NodeFactory.createURI("uno");
    Node dos = NodeFactory.createURI("dos");
    Node tres = NodeFactory.createURI("tres");
    ElementUnion union = new ElementUnion();
    ElementPathBlock epb = new ElementPathBlock();
    Triple t = new Triple(one, two, Var.alloc(v));
    epb.addTriple(t);
    union.addElement(epb);
    ElementPathBlock epb2 = new ElementPathBlock();
    t = new Triple(uno, dos, tres);
    epb2.addTriple(t);
    union.addElement(epb2);
    WhereValidator visitor = new WhereValidator(union);
    query.getQueryPattern().visit(visitor);
    assertTrue(visitor.matching);
    builder.setVar(v, NodeFactory.createURI("three"));
    query = builder.build();
    union = new ElementUnion();
    epb = new ElementPathBlock();
    t = new Triple(one, two, three);
    epb.addTriple(t);
    union.addElement(epb);
    epb2 = new ElementPathBlock();
    t = new Triple(uno, dos, tres);
    epb2.addTriple(t);
    union.addElement(epb2);
    visitor = new WhereValidator(union);
    query.getQueryPattern().visit(visitor);
    assertTrue(visitor.matching);
}
Also used : Triple(org.apache.jena.graph.Triple) FrontsTriple(org.apache.jena.graph.FrontsTriple) ElementUnion(org.apache.jena.sparql.syntax.ElementUnion) ElementSubQuery(org.apache.jena.sparql.syntax.ElementSubQuery) Query(org.apache.jena.query.Query) WhereValidator(org.apache.jena.arq.querybuilder.WhereValidator) Node(org.apache.jena.graph.Node) SelectBuilder(org.apache.jena.arq.querybuilder.SelectBuilder) ElementPathBlock(org.apache.jena.sparql.syntax.ElementPathBlock) ContractTest(org.xenei.junit.contract.ContractTest)

Example 34 with ElementPathBlock

use of org.apache.jena.sparql.syntax.ElementPathBlock in project jena by apache.

the class WhereClauseTest method testAddGraph_frontsTriple.

@ContractTest
public void testAddGraph_frontsTriple() {
    final Node s = NodeFactory.createURI("s");
    final Node p = NodeFactory.createURI("p");
    final Node o = NodeFactory.createURI("o");
    FrontsTriple ft = new FrontsTriple() {

        @Override
        public Triple asTriple() {
            return new Triple(s, p, o);
        }
    };
    WhereClause<?> whereClause = getProducer().newInstance();
    AbstractQueryBuilder<?> builder = whereClause.addGraph("<g>", ft);
    Query query = builder.build();
    ElementPathBlock epb = new ElementPathBlock();
    ElementNamedGraph eng = new ElementNamedGraph(NodeFactory.createURI("g"), epb);
    epb.addTriplePath(new TriplePath(new Triple(s, p, o)));
    WhereValidator visitor = new WhereValidator(eng);
    query.getQueryPattern().visit(visitor);
    assertTrue(visitor.matching);
}
Also used : Triple(org.apache.jena.graph.Triple) FrontsTriple(org.apache.jena.graph.FrontsTriple) ElementNamedGraph(org.apache.jena.sparql.syntax.ElementNamedGraph) ElementSubQuery(org.apache.jena.sparql.syntax.ElementSubQuery) Query(org.apache.jena.query.Query) FrontsTriple(org.apache.jena.graph.FrontsTriple) WhereValidator(org.apache.jena.arq.querybuilder.WhereValidator) Node(org.apache.jena.graph.Node) TriplePath(org.apache.jena.sparql.core.TriplePath) ElementPathBlock(org.apache.jena.sparql.syntax.ElementPathBlock) ContractTest(org.xenei.junit.contract.ContractTest)

Example 35 with ElementPathBlock

use of org.apache.jena.sparql.syntax.ElementPathBlock in project jena by apache.

the class WhereClauseTest method testSetVarsInTriple.

@ContractTest
public void testSetVarsInTriple() {
    Var v = Var.alloc("v");
    Node one = NodeFactory.createURI("one");
    Node two = NodeFactory.createURI("two");
    Node three = NodeFactory.createURI("three");
    Node four = NodeFactory.createURI("four");
    WhereClause<?> whereClause = getProducer().newInstance();
    AbstractQueryBuilder<?> builder = whereClause.addWhere(new Triple(one, two, v));
    TriplePath tp = new TriplePath(new Triple(one, two, v));
    ElementPathBlock epb = new ElementPathBlock();
    epb.addTriple(tp);
    WhereValidator visitor = new WhereValidator(epb);
    builder.build().getQueryPattern().visit(visitor);
    assertTrue(visitor.matching);
    builder.setVar(v, three);
    tp = new TriplePath(new Triple(one, two, three));
    epb = new ElementPathBlock();
    epb.addTriple(tp);
    visitor = new WhereValidator(epb);
    builder.build().getQueryPattern().visit(visitor);
    assertTrue(visitor.matching);
    builder.setVar(v, four);
    tp = new TriplePath(new Triple(one, two, four));
    epb = new ElementPathBlock();
    epb.addTriple(tp);
    visitor = new WhereValidator(epb);
    builder.build().getQueryPattern().visit(visitor);
    assertTrue(visitor.matching);
    builder.setVar(v, null);
    tp = new TriplePath(new Triple(one, two, v));
    epb = new ElementPathBlock();
    epb.addTriple(tp);
    visitor = new WhereValidator(epb);
    builder.build().getQueryPattern().visit(visitor);
    assertTrue(visitor.matching);
}
Also used : Triple(org.apache.jena.graph.Triple) FrontsTriple(org.apache.jena.graph.FrontsTriple) ExprVar(org.apache.jena.sparql.expr.ExprVar) Var(org.apache.jena.sparql.core.Var) WhereValidator(org.apache.jena.arq.querybuilder.WhereValidator) Node(org.apache.jena.graph.Node) TriplePath(org.apache.jena.sparql.core.TriplePath) ElementPathBlock(org.apache.jena.sparql.syntax.ElementPathBlock) ContractTest(org.xenei.junit.contract.ContractTest)

Aggregations

ElementPathBlock (org.apache.jena.sparql.syntax.ElementPathBlock)78 Triple (org.apache.jena.graph.Triple)62 WhereValidator (org.apache.jena.arq.querybuilder.WhereValidator)60 TriplePath (org.apache.jena.sparql.core.TriplePath)56 Test (org.junit.Test)44 Query (org.apache.jena.query.Query)32 ElementSubQuery (org.apache.jena.sparql.syntax.ElementSubQuery)27 Node (org.apache.jena.graph.Node)26 ContractTest (org.xenei.junit.contract.ContractTest)25 SelectBuilder (org.apache.jena.arq.querybuilder.SelectBuilder)22 FrontsTriple (org.apache.jena.graph.FrontsTriple)22 ElementOptional (org.apache.jena.sparql.syntax.ElementOptional)18 Var (org.apache.jena.sparql.core.Var)14 ElementGroup (org.apache.jena.sparql.syntax.ElementGroup)11 Element (org.apache.jena.sparql.syntax.Element)10 ElementUnion (org.apache.jena.sparql.syntax.ElementUnion)8 ExprVar (org.apache.jena.sparql.expr.ExprVar)7 ElementNamedGraph (org.apache.jena.sparql.syntax.ElementNamedGraph)7 Quad (org.apache.jena.sparql.core.Quad)5 UpdateModify (org.apache.jena.sparql.modify.request.UpdateModify)5