Search in sources :

Example 6 with ElementTriplesBlock

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

the class labelSearch method buildSyntax.

// Build SPARQL syntax and compile it.
// Not recommended.
private QueryIterator buildSyntax(QueryIterator input, Node nodeVar, String pattern, ExecutionContext execCxt) {
    Var var2 = createNewVar();
    // Triple patterns for   ?x rdfs:label ?hiddenVar
    ElementTriplesBlock elementBGP = new ElementTriplesBlock();
    Triple t = new Triple(nodeVar, RDFS.label.asNode(), var2);
    elementBGP.addTriple(t);
    // Regular expression for  regex(?hiddenVar, "pattern", "i") 
    Expr regex = new E_Regex(new ExprVar(var2.getName()), pattern, "i");
    ElementGroup elementGroup = new ElementGroup();
    elementGroup.addElement(elementBGP);
    elementGroup.addElement(new ElementFilter(regex));
    // Compile it.
    // The better design is to build the Op structure programmatically,
    Op op = Algebra.compile(elementGroup);
    op = Algebra.optimize(op, execCxt.getContext());
    return QC.execute(op, input, execCxt);
}
Also used : Triple(org.apache.jena.graph.Triple) E_Regex(org.apache.jena.sparql.expr.E_Regex) ExprVar(org.apache.jena.sparql.expr.ExprVar) Op(org.apache.jena.sparql.algebra.Op) Expr(org.apache.jena.sparql.expr.Expr) ExprVar(org.apache.jena.sparql.expr.ExprVar) Var(org.apache.jena.sparql.core.Var) ElementFilter(org.apache.jena.sparql.syntax.ElementFilter) ElementTriplesBlock(org.apache.jena.sparql.syntax.ElementTriplesBlock) ElementGroup(org.apache.jena.sparql.syntax.ElementGroup)

Example 7 with ElementTriplesBlock

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

the class UpdateEngineWorker method elementFromQuads.

protected Element elementFromQuads(List<Quad> quads) {
    ElementGroup el = new ElementGroup();
    ElementTriplesBlock x = new ElementTriplesBlock();
    // Maybe empty??
    el.addElement(x);
    Node g = Quad.defaultGraphNodeGenerated;
    for (Quad q : quads) {
        if (q.getGraph() != g) {
            g = q.getGraph();
            x = new ElementTriplesBlock();
            if (g == null || g == Quad.defaultGraphNodeGenerated)
                el.addElement(x);
            else {
                ElementNamedGraph eng = new ElementNamedGraph(g, x);
                el.addElement(eng);
            }
        }
        x.addTriple(q.asTriple());
    }
    return el;
}
Also used : ElementNamedGraph(org.apache.jena.sparql.syntax.ElementNamedGraph) Node(org.apache.jena.graph.Node) ElementTriplesBlock(org.apache.jena.sparql.syntax.ElementTriplesBlock) ElementGroup(org.apache.jena.sparql.syntax.ElementGroup)

Aggregations

ElementTriplesBlock (org.apache.jena.sparql.syntax.ElementTriplesBlock)7 ElementGroup (org.apache.jena.sparql.syntax.ElementGroup)6 Element (org.apache.jena.sparql.syntax.Element)4 Var (org.apache.jena.sparql.core.Var)3 Triple (org.apache.jena.graph.Triple)2 Query (org.apache.jena.query.Query)2 Test (org.junit.Test)2 ContractTest (org.xenei.junit.contract.ContractTest)2 Node (org.apache.jena.graph.Node)1 Op (org.apache.jena.sparql.algebra.Op)1 E_Random (org.apache.jena.sparql.expr.E_Random)1 E_Regex (org.apache.jena.sparql.expr.E_Regex)1 Expr (org.apache.jena.sparql.expr.Expr)1 ExprVar (org.apache.jena.sparql.expr.ExprVar)1 ElementFilter (org.apache.jena.sparql.syntax.ElementFilter)1 ElementNamedGraph (org.apache.jena.sparql.syntax.ElementNamedGraph)1