Search in sources :

Example 71 with ElementPathBlock

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

the class WhereHandlerTest method testListInTriple.

@Test
public void testListInTriple() {
    handler.addWhere(new TriplePath(new Triple(handler.list("<one>", "?var", "'three'"), ResourceFactory.createResource("foo").asNode(), ResourceFactory.createResource("bar").asNode())));
    handler.build();
    P_Link first = new P_Link(RDF.first.asNode());
    P_Link rest = new P_Link(RDF.rest.asNode());
    Node n = NodeFactory.createURI("foo");
    P_Link foo = new P_Link(n);
    // ElementPathBlock epb = (ElementPathBlock) query.getQueryPattern();
    ElementPathBlock epb = new ElementPathBlock();
    Node list = NodeFactory.createBlankNode();
    Node s = list;
    epb.addTriple(new TriplePath(s, first, NodeFactory.createURI("one")));
    Node o = NodeFactory.createBlankNode();
    epb.addTriple(new TriplePath(s, rest, o));
    s = o;
    epb.addTriple(new TriplePath(s, first, Var.alloc("var")));
    o = NodeFactory.createBlankNode();
    epb.addTriple(new TriplePath(s, rest, o));
    s = o;
    epb.addTriple(new TriplePath(s, first, NodeFactory.createLiteral("three")));
    epb.addTriple(new TriplePath(s, rest, RDF.nil.asNode()));
    epb.addTriple(new TriplePath(list, foo, NodeFactory.createURI("bar")));
    WhereValidator visitor = new WhereValidator(epb);
    query.getQueryPattern().visit(visitor);
    assertTrue(visitor.matching);
}
Also used : Triple(org.apache.jena.graph.Triple) WhereValidator(org.apache.jena.arq.querybuilder.WhereValidator) Node(org.apache.jena.graph.Node) TriplePath(org.apache.jena.sparql.core.TriplePath) P_Link(org.apache.jena.sparql.path.P_Link) ElementPathBlock(org.apache.jena.sparql.syntax.ElementPathBlock) Test(org.junit.Test)

Example 72 with ElementPathBlock

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

the class WhereHandlerTest method testAddWhereObjectsWithPath.

@Test
public void testAddWhereObjectsWithPath() {
    PrefixMapping pmap = new PrefixMappingImpl();
    pmap.setNsPrefix("ts", "urn:test:");
    Path path = PathParser.parse("ts:two/ts:dos", pmap);
    handler.addWhere(new TriplePath(NodeFactory.createURI("one"), path, ResourceFactory.createLangLiteral("three", "en-US").asNode()));
    handler.build();
    TriplePath tp = new TriplePath(NodeFactory.createURI("one"), path, ResourceFactory.createLangLiteral("three", "en-US").asNode());
    ElementPathBlock epb = new ElementPathBlock();
    epb.addTriple(tp);
    WhereValidator wv = new WhereValidator(epb);
    query.getQueryPattern().visit(wv);
    assertTrue(wv.matching);
}
Also used : TriplePath(org.apache.jena.sparql.core.TriplePath) Path(org.apache.jena.sparql.path.Path) PrefixMapping(org.apache.jena.shared.PrefixMapping) 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) Test(org.junit.Test)

Example 73 with ElementPathBlock

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

the class WhereHandlerTest method testAddUnionToExisting.

@Test
public void testAddUnionToExisting() {
    handler.addWhere(new TriplePath(new Triple(NodeFactory.createURI("s"), NodeFactory.createURI("p"), NodeFactory.createURI("o"))));
    SelectBuilder sb = new SelectBuilder();
    sb.addWhere(new Triple(NodeFactory.createURI("one"), NodeFactory.createURI("two"), NodeFactory.createURI("three")));
    handler.addUnion(sb);
    handler.build();
    TriplePath tp1 = new TriplePath(new Triple(NodeFactory.createURI("s"), NodeFactory.createURI("p"), NodeFactory.createURI("o")));
    ElementPathBlock epb1 = new ElementPathBlock();
    epb1.addTriple(tp1);
    TriplePath tp2 = new TriplePath(new Triple(NodeFactory.createURI("one"), NodeFactory.createURI("two"), NodeFactory.createURI("three")));
    ElementPathBlock epb2 = new ElementPathBlock();
    epb2.addTriple(tp2);
    ElementUnion union = new ElementUnion();
    union.addElement(epb1);
    union.addElement(epb2);
    WhereValidator visitor = new WhereValidator(union);
    handler.getQueryPattern().visit(visitor);
    assertTrue(visitor.matching);
}
Also used : Triple(org.apache.jena.graph.Triple) ElementUnion(org.apache.jena.sparql.syntax.ElementUnion) WhereValidator(org.apache.jena.arq.querybuilder.WhereValidator) TriplePath(org.apache.jena.sparql.core.TriplePath) SelectBuilder(org.apache.jena.arq.querybuilder.SelectBuilder) ElementPathBlock(org.apache.jena.sparql.syntax.ElementPathBlock) Test(org.junit.Test)

Example 74 with ElementPathBlock

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

the class WhereHandlerTest method testSetVarsInOptional.

@Test
public void testSetVarsInOptional() {
    Var v = Var.alloc("v");
    handler.addOptional(new TriplePath(new Triple(NodeFactory.createURI("one"), NodeFactory.createURI("two"), v)));
    handler.build();
    TriplePath tp = new TriplePath(new Triple(NodeFactory.createURI("one"), NodeFactory.createURI("two"), v));
    ElementPathBlock epb = new ElementPathBlock();
    epb.addTriple(tp);
    ElementOptional opt = new ElementOptional(epb);
    WhereValidator wv = new WhereValidator(opt);
    query.getQueryPattern().visit(wv);
    assertTrue(wv.matching);
    Map<Var, Node> values = new HashMap<>();
    values.put(v, NodeFactory.createURI("three"));
    handler.setVars(values);
    handler.build();
    tp = new TriplePath(new Triple(NodeFactory.createURI("one"), NodeFactory.createURI("two"), NodeFactory.createURI("three")));
    epb = new ElementPathBlock();
    epb.addTriple(tp);
    opt = new ElementOptional(epb);
    wv = new WhereValidator(opt);
    query.getQueryPattern().visit(wv);
    assertTrue(wv.matching);
}
Also used : Triple(org.apache.jena.graph.Triple) ElementOptional(org.apache.jena.sparql.syntax.ElementOptional) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) 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) Test(org.junit.Test)

Example 75 with ElementPathBlock

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

the class ElementTransformSubst method transform.

@Override
public Element transform(ElementPathBlock el) {
    ElementPathBlock epb = new ElementPathBlock();
    boolean changed = false;
    for (TriplePath p : el.getPattern()) {
        TriplePath p2 = transform(p);
        changed = changed || p != p2;
        epb.addTriplePath(p2);
    }
    if (changed)
        return epb;
    return el;
}
Also used : TriplePath(org.apache.jena.sparql.core.TriplePath) ElementPathBlock(org.apache.jena.sparql.syntax.ElementPathBlock)

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