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);
}
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);
}
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));
}
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(")");
}
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;
}
Aggregations