Search in sources :

Example 1 with WhereBuilder

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

the class WhereHandlerTest method testMakeSubQueryFromWhere.

@Test
public void testMakeSubQueryFromWhere() {
    AbstractQueryBuilder<?> sb = new WhereBuilder().addWhere("?x", RDF.type, RDF.Alt);
    ElementSubQuery esq = handler.makeSubQuery(sb);
    Triple t1 = new Triple(NodeFactory.createVariable("x"), RDF.type.asNode(), RDF.Alt.asNode());
    TriplePath tp = new TriplePath(t1);
    ElementPathBlock epb = new ElementPathBlock();
    epb.addTriple(tp);
    Query q = new Query();
    q.setQuerySelectType();
    q.setQueryResultStar(true);
    q.setQueryPattern(epb);
    ElementSubQuery esq2 = new ElementSubQuery(q);
    WhereValidator wv = new WhereValidator(esq2);
    esq.visit(wv);
    assertTrue(wv.matching);
}
Also used : Triple(org.apache.jena.graph.Triple) ElementSubQuery(org.apache.jena.sparql.syntax.ElementSubQuery) ElementSubQuery(org.apache.jena.sparql.syntax.ElementSubQuery) Query(org.apache.jena.query.Query) WhereValidator(org.apache.jena.arq.querybuilder.WhereValidator) WhereBuilder(org.apache.jena.arq.querybuilder.WhereBuilder) TriplePath(org.apache.jena.sparql.core.TriplePath) ElementPathBlock(org.apache.jena.sparql.syntax.ElementPathBlock) Test(org.junit.Test)

Example 2 with WhereBuilder

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

the class QBQuadHolderTest method namedTest_Var.

@Test
public void namedTest_Var() {
    WhereBuilder builder = new WhereBuilder();
    Node g = NodeFactory.createURI("g");
    List<Triple> tLst = new ArrayList<Triple>();
    Node s = NodeFactory.createURI("s");
    Node p = NodeFactory.createVariable("p");
    Node o = NodeFactory.createURI("o");
    builder.addGraph(g, 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.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(g, 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)

Example 3 with WhereBuilder

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

the class QBQuadHolderTest method mixedTest.

@Test
public void mixedTest() {
    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 g = NodeFactory.createURI("g");
    Node s2 = NodeFactory.createURI("s2");
    Node p2 = NodeFactory.createURI("p2");
    Node o2 = NodeFactory.createURI("o2");
    tLst.add(new Triple(s2, p2, o2));
    builder.addGraph(g, 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(g, 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 4 with WhereBuilder

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

the class QBQuadHolderTest method namedTest.

@Test
public void namedTest() {
    WhereBuilder builder = new WhereBuilder();
    Node g = NodeFactory.createURI("g");
    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.addGraph(g, 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.addGraph(g, s2, p2, o2);
    holder = new QBQuadHolder(builder);
    List<Quad> lst = holder.getQuads().toList();
    assertEquals(2, lst.size());
    assertEquals(new Quad(g, 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) Node(org.apache.jena.graph.Node) ArrayList(java.util.ArrayList) WhereBuilder(org.apache.jena.arq.querybuilder.WhereBuilder) Test(org.junit.Test)

Example 5 with WhereBuilder

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

the class WhereClauseTest method testAddWhereWhereClause.

@ContractTest
public void testAddWhereWhereClause() {
    WhereBuilder whereBuilder = new WhereBuilder().addWhere(new TriplePath(new Triple(NodeFactory.createURI("one"), NodeFactory.createURI("two"), NodeFactory.createURI("three"))));
    WhereClause<?> whereClause = getProducer().newInstance();
    AbstractQueryBuilder<?> builder = whereClause.addWhere(whereBuilder);
    ElementPathBlock epb = new ElementPathBlock();
    Triple t = new Triple(NodeFactory.createURI("one"), NodeFactory.createURI("two"), NodeFactory.createURI("three"));
    epb.addTriple(t);
    WhereValidator 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) WhereBuilder(org.apache.jena.arq.querybuilder.WhereBuilder) TriplePath(org.apache.jena.sparql.core.TriplePath) ElementPathBlock(org.apache.jena.sparql.syntax.ElementPathBlock) ContractTest(org.xenei.junit.contract.ContractTest)

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