Search in sources :

Example 86 with WhereValidator

use of org.apache.jena.arq.querybuilder.WhereValidator 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 87 with WhereValidator

use of org.apache.jena.arq.querybuilder.WhereValidator 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 88 with WhereValidator

use of org.apache.jena.arq.querybuilder.WhereValidator 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 89 with WhereValidator

use of org.apache.jena.arq.querybuilder.WhereValidator 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 90 with WhereValidator

use of org.apache.jena.arq.querybuilder.WhereValidator in project jena by apache.

the class WhereHandlerTest method testAddValueVar_pfx_obj_array.

@Test
public void testAddValueVar_pfx_obj_array() {
    Node two = NodeFactory.createURI("two");
    handler.addValueVar(query.getPrefixMapping(), "?v", "<one>", two);
    handler.build();
    Var v = Var.alloc("v");
    ElementData edat = new ElementData();
    edat.add(v);
    Binding binding1 = BindingFactory.binding(v, NodeFactory.createURI("one"));
    edat.add(binding1);
    Binding binding2 = BindingFactory.binding(v, two);
    edat.add(binding2);
    WhereValidator visitor = new WhereValidator(edat);
    query.getQueryPattern().visit(visitor);
    assertTrue(visitor.matching);
}
Also used : Binding(org.apache.jena.sparql.engine.binding.Binding) Var(org.apache.jena.sparql.core.Var) WhereValidator(org.apache.jena.arq.querybuilder.WhereValidator) Node(org.apache.jena.graph.Node) ElementData(org.apache.jena.sparql.syntax.ElementData) Test(org.junit.Test)

Aggregations

WhereValidator (org.apache.jena.arq.querybuilder.WhereValidator)90 ElementPathBlock (org.apache.jena.sparql.syntax.ElementPathBlock)60 Triple (org.apache.jena.graph.Triple)54 TriplePath (org.apache.jena.sparql.core.TriplePath)49 Test (org.junit.Test)47 Query (org.apache.jena.query.Query)42 ElementSubQuery (org.apache.jena.sparql.syntax.ElementSubQuery)42 ContractTest (org.xenei.junit.contract.ContractTest)42 Var (org.apache.jena.sparql.core.Var)34 Node (org.apache.jena.graph.Node)30 SelectBuilder (org.apache.jena.arq.querybuilder.SelectBuilder)22 FrontsTriple (org.apache.jena.graph.FrontsTriple)22 ExprVar (org.apache.jena.sparql.expr.ExprVar)21 ElementData (org.apache.jena.sparql.syntax.ElementData)18 ElementOptional (org.apache.jena.sparql.syntax.ElementOptional)16 HashMap (java.util.HashMap)10 ElementUnion (org.apache.jena.sparql.syntax.ElementUnion)8 LinkedHashMap (java.util.LinkedHashMap)7 Binding (org.apache.jena.sparql.engine.binding.Binding)6 E_Random (org.apache.jena.sparql.expr.E_Random)6