Search in sources :

Example 6 with WhereBuilder

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

the class QBQuadHolderTest method anonymousTest_Var.

@Test
public void anonymousTest_Var() {
    WhereBuilder builder = new WhereBuilder();
    List<Triple> tLst = new ArrayList<Triple>();
    Node s = NodeFactory.createURI("s");
    Node p = NodeFactory.createVariable("p");
    Node o = NodeFactory.createURI("o");
    builder.addWhere(s, p, o);
    Node s2 = NodeFactory.createURI("s2");
    Node p2 = NodeFactory.createURI("p2");
    Node o2 = NodeFactory.createURI("o2");
    tLst.add(new Triple(s, p2, o));
    tLst.add(new Triple(s2, p2, o2));
    builder.addWhere(s2, p, o2);
    holder = new QBQuadHolder(builder);
    Map<Var, Node> map = new HashMap<>();
    map.put(Var.alloc(p), p2);
    holder.setValues(map);
    List<Quad> lst = holder.getQuads().toList();
    assertEquals(2, lst.size());
    assertEquals(new Quad(Quad.defaultGraphNodeGenerated, tLst.get(0)), lst.get(0));
    assertEquals(new Quad(Quad.defaultGraphNodeGenerated, tLst.get(1)), lst.get(1));
}
Also used : Triple(org.apache.jena.graph.Triple) Quad(org.apache.jena.sparql.core.Quad) HashMap(java.util.HashMap) Var(org.apache.jena.sparql.core.Var) Node(org.apache.jena.graph.Node) ArrayList(java.util.ArrayList) WhereBuilder(org.apache.jena.arq.querybuilder.WhereBuilder) Test(org.junit.Test)

Example 7 with WhereBuilder

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

the class QBQuadHolderTest method anonymousTest.

@Test
public void anonymousTest() {
    WhereBuilder builder = new WhereBuilder();
    List<Triple> tLst = new ArrayList<Triple>();
    Node s = NodeFactory.createURI("s");
    Node p = NodeFactory.createURI("p");
    Node o = NodeFactory.createURI("o");
    tLst.add(new Triple(s, p, o));
    builder.addWhere(s, p, o);
    Node s2 = NodeFactory.createURI("s2");
    Node p2 = NodeFactory.createURI("p2");
    Node o2 = NodeFactory.createURI("o2");
    tLst.add(new Triple(s2, p2, o2));
    builder.addWhere(s2, p2, o2);
    holder = new QBQuadHolder(builder);
    List<Quad> lst = holder.getQuads().toList();
    assertEquals(2, lst.size());
    assertEquals(new Quad(Quad.defaultGraphNodeGenerated, tLst.get(0)), lst.get(0));
    assertEquals(new Quad(Quad.defaultGraphNodeGenerated, tLst.get(1)), lst.get(1));
}
Also used : Triple(org.apache.jena.graph.Triple) Quad(org.apache.jena.sparql.core.Quad) Node(org.apache.jena.graph.Node) ArrayList(java.util.ArrayList) WhereBuilder(org.apache.jena.arq.querybuilder.WhereBuilder) Test(org.junit.Test)

Example 8 with WhereBuilder

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

the class QBQuadHolderTest method mixedTest_Var.

@Test
public void mixedTest_Var() {
    WhereBuilder builder = new WhereBuilder();
    List<Triple> tLst = new ArrayList<Triple>();
    Node s = NodeFactory.createURI("s");
    Node p = NodeFactory.createVariable("p");
    Node o = NodeFactory.createURI("o");
    builder.addWhere(s, p, o);
    Node g = NodeFactory.createURI("g");
    Node s2 = NodeFactory.createURI("s2");
    Node p2 = NodeFactory.createURI("p2");
    Node o2 = NodeFactory.createURI("o2");
    tLst.add(new Triple(s, p2, o));
    tLst.add(new Triple(s2, p2, o2));
    builder.addGraph(g, s2, p, o2);
    holder = new QBQuadHolder(builder);
    Map<Var, Node> map = new HashMap<>();
    map.put(Var.alloc(p), p2);
    holder.setValues(map);
    List<Quad> lst = holder.getQuads().toList();
    assertEquals(2, lst.size());
    assertEquals(new Quad(Quad.defaultGraphNodeGenerated, tLst.get(0)), lst.get(0));
    assertEquals(new Quad(g, tLst.get(1)), lst.get(1));
}
Also used : Triple(org.apache.jena.graph.Triple) Quad(org.apache.jena.sparql.core.Quad) HashMap(java.util.HashMap) Var(org.apache.jena.sparql.core.Var) Node(org.apache.jena.graph.Node) ArrayList(java.util.ArrayList) WhereBuilder(org.apache.jena.arq.querybuilder.WhereBuilder) Test(org.junit.Test)

Aggregations

WhereBuilder (org.apache.jena.arq.querybuilder.WhereBuilder)8 Triple (org.apache.jena.graph.Triple)8 Test (org.junit.Test)7 ArrayList (java.util.ArrayList)6 Node (org.apache.jena.graph.Node)6 Quad (org.apache.jena.sparql.core.Quad)6 HashMap (java.util.HashMap)3 Var (org.apache.jena.sparql.core.Var)3 WhereValidator (org.apache.jena.arq.querybuilder.WhereValidator)2 TriplePath (org.apache.jena.sparql.core.TriplePath)2 ElementPathBlock (org.apache.jena.sparql.syntax.ElementPathBlock)2 FrontsTriple (org.apache.jena.graph.FrontsTriple)1 Query (org.apache.jena.query.Query)1 ElementSubQuery (org.apache.jena.sparql.syntax.ElementSubQuery)1 ContractTest (org.xenei.junit.contract.ContractTest)1