Search in sources :

Example 76 with ElementPathBlock

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

the class ARQParserBase method createQueryPattern.

protected ElementGroup createQueryPattern(Template t) {
    ElementGroup elg = new ElementGroup();
    Map<Node, BasicPattern> graphs = t.getGraphPattern();
    for (Node n : graphs.keySet()) {
        Element el = new ElementPathBlock(graphs.get(n));
        if (!Quad.defaultGraphNodeGenerated.equals(n)) {
            ElementGroup e = new ElementGroup();
            e.addElement(el);
            el = new ElementNamedGraph(n, e);
        }
        elg.addElement(el);
    }
    return elg;
}
Also used : ElementNamedGraph(org.apache.jena.sparql.syntax.ElementNamedGraph) Node(org.apache.jena.graph.Node) Element(org.apache.jena.sparql.syntax.Element) BasicPattern(org.apache.jena.sparql.core.BasicPattern) ElementGroup(org.apache.jena.sparql.syntax.ElementGroup) ElementPathBlock(org.apache.jena.sparql.syntax.ElementPathBlock)

Example 77 with ElementPathBlock

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

the class WhereHandler method addWhere.

/**
 * Add the triple path to the where clause
 *
 * @param t The triple path to add.
 * @throws IllegalArgumentException If the triple path is not a valid triple
 * path for a where clause.
 */
public void addWhere(TriplePath t) throws IllegalArgumentException {
    testTriple(t);
    ElementGroup eg = getClause();
    List<Element> lst = eg.getElements();
    if (lst.isEmpty()) {
        ElementPathBlock epb = new ElementPathBlock();
        epb.addTriple(t);
        eg.addElement(epb);
    } else {
        Element e = lst.get(lst.size() - 1);
        if (e instanceof ElementTriplesBlock && t.isTriple()) {
            ElementTriplesBlock etb = (ElementTriplesBlock) e;
            etb.addTriple(t.asTriple());
        } else if (e instanceof ElementPathBlock) {
            ElementPathBlock epb = (ElementPathBlock) e;
            epb.addTriple(t);
        } else {
            ElementPathBlock etb = new ElementPathBlock();
            etb.addTriple(t);
            eg.addElement(etb);
        }
    }
}
Also used : Element(org.apache.jena.sparql.syntax.Element) ElementTriplesBlock(org.apache.jena.sparql.syntax.ElementTriplesBlock) ElementGroup(org.apache.jena.sparql.syntax.ElementGroup) ElementPathBlock(org.apache.jena.sparql.syntax.ElementPathBlock)

Example 78 with ElementPathBlock

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

the class AskBuilderTest method testList.

@Test
public void testList() {
    builder.addWhere(builder.list("<one>", "?two", "'three'"), "<foo>", "<bar>");
    Query query = builder.build();
    Node one = NodeFactory.createURI("one");
    Node two = Var.alloc("two").asNode();
    Node three = NodeFactory.createLiteral("three");
    Node foo = NodeFactory.createURI("foo");
    Node bar = NodeFactory.createURI("bar");
    ElementPathBlock epb = new ElementPathBlock();
    Node firstObject = NodeFactory.createBlankNode();
    Node secondObject = NodeFactory.createBlankNode();
    Node thirdObject = NodeFactory.createBlankNode();
    epb.addTriplePath(new TriplePath(new Triple(firstObject, RDF.first.asNode(), one)));
    epb.addTriplePath(new TriplePath(new Triple(firstObject, RDF.rest.asNode(), secondObject)));
    epb.addTriplePath(new TriplePath(new Triple(secondObject, RDF.first.asNode(), two)));
    epb.addTriplePath(new TriplePath(new Triple(secondObject, RDF.rest.asNode(), thirdObject)));
    epb.addTriplePath(new TriplePath(new Triple(thirdObject, RDF.first.asNode(), three)));
    epb.addTriplePath(new TriplePath(new Triple(thirdObject, RDF.rest.asNode(), RDF.nil.asNode())));
    epb.addTriplePath(new TriplePath(new Triple(firstObject, foo, bar)));
    WhereValidator visitor = new WhereValidator(epb);
    query.getQueryPattern().visit(visitor);
    assertTrue(visitor.matching);
}
Also used : Triple(org.apache.jena.graph.Triple) Query(org.apache.jena.query.Query) Node(org.apache.jena.graph.Node) TriplePath(org.apache.jena.sparql.core.TriplePath) ElementPathBlock(org.apache.jena.sparql.syntax.ElementPathBlock) Test(org.junit.Test) AbstractRegexpBasedTest(org.apache.jena.arq.AbstractRegexpBasedTest)

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