Search in sources :

Example 46 with Var

use of org.apache.jena.sparql.core.Var in project jena by apache.

the class strSplit method execEvaluated.

@Override
public QueryIterator execEvaluated(final Binding binding, final Node subject, final Node predicate, final PropFuncArg object, final ExecutionContext execCxt) {
    if (!Var.isVar(subject))
        throw new ExprEvalException("Subject is not a variable (" + subject + ")");
    if (object.getArgListSize() != 2)
        throw new ExprEvalException("Object list must contain exactly two arguments, the string to split and a regular expression");
    String s = object.getArg(0).getLiteralLexicalForm();
    String regex = object.getArg(1).getLiteralLexicalForm();
    final Var subjectVar = Var.alloc(subject);
    // StrUtils will also trim whitespace
    String[] tokens = StrUtils.split(s, regex);
    Iterator<Binding> it = Iter.map(Arrays.asList(tokens).iterator(), item -> BindingFactory.binding(binding, subjectVar, NodeFactory.createLiteral(item)));
    return new QueryIterPlainWrapper(it, execCxt);
}
Also used : Binding(org.apache.jena.sparql.engine.binding.Binding) QueryIterPlainWrapper(org.apache.jena.sparql.engine.iterator.QueryIterPlainWrapper) Var(org.apache.jena.sparql.core.Var) ExprEvalException(org.apache.jena.sparql.expr.ExprEvalException)

Example 47 with Var

use of org.apache.jena.sparql.core.Var in project jena by apache.

the class QueryTest method convertToStrings.

private ResultSetRewindable convertToStrings(ResultSetRewindable resultsActual) {
    List<Binding> bindings = new ArrayList<>();
    while (resultsActual.hasNext()) {
        Binding b = resultsActual.nextBinding();
        BindingMap b2 = BindingFactory.create();
        for (String vn : resultsActual.getResultVars()) {
            Var v = Var.alloc(vn);
            Node n = b.get(v);
            String s;
            if (n == null)
                s = "";
            else if (n.isBlank())
                s = "_:" + n.getBlankNodeLabel();
            else
                s = NodeFunctions.str(n);
            b2.add(v, NodeFactory.createLiteral(s));
        }
        bindings.add(b2);
    }
    ResultSet rs = new ResultSetStream(resultsActual.getResultVars(), null, new QueryIterPlainWrapper(bindings.iterator()));
    return ResultSetFactory.makeRewindable(rs);
}
Also used : Binding(org.apache.jena.sparql.engine.binding.Binding) QueryIterPlainWrapper(org.apache.jena.sparql.engine.iterator.QueryIterPlainWrapper) Var(org.apache.jena.sparql.core.Var) RDFNode(org.apache.jena.rdf.model.RDFNode) Node(org.apache.jena.graph.Node) ArrayList(java.util.ArrayList) ResultSet(org.apache.jena.query.ResultSet) BindingMap(org.apache.jena.sparql.engine.binding.BindingMap) ResultSetStream(org.apache.jena.sparql.engine.ResultSetStream)

Example 48 with Var

use of org.apache.jena.sparql.core.Var in project jena by apache.

the class TestSolverTDB method exec.

private static ResultSet exec(String pattern, Graph graph) {
    Op op = SSE.parseOp(pattern, pmap);
    List<Var> vars = new ArrayList<>();
    vars.addAll(OpVars.visibleVars(op));
    QueryIterator qIter = Algebra.exec(op, graph);
    return ResultSetFactory.create(qIter, Var.varNames(vars));
}
Also used : Op(org.apache.jena.sparql.algebra.Op) QueryIterator(org.apache.jena.sparql.engine.QueryIterator) Var(org.apache.jena.sparql.core.Var) ArrayList(java.util.ArrayList)

Example 49 with Var

use of org.apache.jena.sparql.core.Var in project jena by apache.

the class TableWriter method output.

private static void output(Binding binding, IndentedWriter out, SerializationContext sCxt) {
    out.print("(row");
    for (Iterator<Var> iter = binding.vars(); iter.hasNext(); ) {
        Var v = iter.next();
        Node n = binding.get(v);
        out.print(" ");
        out.print(Plan.startMarker2);
        out.print(FmtUtils.stringForNode(v));
        out.print(" ");
        out.print(FmtUtils.stringForNode(n));
        out.print(Plan.finishMarker2);
    }
    out.print(")");
}
Also used : Var(org.apache.jena.sparql.core.Var) Node(org.apache.jena.graph.Node)

Example 50 with Var

use of org.apache.jena.sparql.core.Var in project jena by apache.

the class GraphSPARQLService method graphBaseFind.

//    @Override
//    public Capabilities getCapabilities()
//    { 
//    	if (capabilities == null)
//            capabilities = new AllCapabilities()
//        	  { @Override public boolean handlesLiteralTyping() { return false; } };
//        return capabilities;
//    }
@Override
protected ExtendedIterator<Triple> graphBaseFind(Triple m) {
    Node s = m.getMatchSubject();
    Var sVar = null;
    if (s == null) {
        sVar = Var.alloc("s");
        s = sVar;
    }
    Node p = m.getMatchPredicate();
    Var pVar = null;
    if (p == null) {
        pVar = Var.alloc("p");
        p = pVar;
    }
    Node o = m.getMatchObject();
    Var oVar = null;
    if (o == null) {
        oVar = Var.alloc("o");
        o = oVar;
    }
    Triple triple = new Triple(s, p, o);
    // Evaluate as an algebra expression
    BasicPattern pattern = new BasicPattern();
    pattern.add(triple);
    Op op = new OpBGP(pattern);
    //        return WrappedIterator.createNoRemove(triples.iterator()) ;
    return null;
}
Also used : Triple(org.apache.jena.graph.Triple) Op(org.apache.jena.sparql.algebra.Op) Var(org.apache.jena.sparql.core.Var) Node(org.apache.jena.graph.Node) OpBGP(org.apache.jena.sparql.algebra.op.OpBGP) BasicPattern(org.apache.jena.sparql.core.BasicPattern)

Aggregations

Var (org.apache.jena.sparql.core.Var)264 Node (org.apache.jena.graph.Node)83 ArrayList (java.util.ArrayList)53 Test (org.junit.Test)47 Binding (org.apache.jena.sparql.engine.binding.Binding)33 VarExprList (org.apache.jena.sparql.core.VarExprList)30 Op (org.apache.jena.sparql.algebra.Op)29 Expr (org.apache.jena.sparql.expr.Expr)28 Triple (org.apache.jena.graph.Triple)17 HashMap (java.util.HashMap)15 ContractTest (org.xenei.junit.contract.ContractTest)13 BindingMap (org.apache.jena.sparql.engine.binding.BindingMap)12 Query (org.apache.jena.query.Query)11 ExprList (org.apache.jena.sparql.expr.ExprList)11 SortCondition (org.apache.jena.query.SortCondition)10 ExprVar (org.apache.jena.sparql.expr.ExprVar)10 HashSet (java.util.HashSet)9 Pair (org.apache.jena.atlas.lib.Pair)9 SqlColumn (org.apache.jena.sdb.core.sqlexpr.SqlColumn)9 QueryIterator (org.apache.jena.sparql.engine.QueryIterator)9