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;
}
use of org.apache.jena.sparql.core.Var in project jena by apache.
the class ExprTransformExpand method transform.
@Override
public Expr transform(ExprFunctionN func, ExprList args) {
ExprFunction f = func.getFunction();
if (this.shouldExpand(f)) {
UserDefinedFunctionDefinition def = this.definitions.get(f.getFunction().getFunctionIRI());
UserDefinedFunction uFunc = (UserDefinedFunction) def.newFunctionInstance();
//Need to watch out for the case where the arguments supplied to the invoked
//function are in a different order to the arguments supplied to the defined
//function
//Thus we will build the list of arguments used to expand the inner function
//manually
List<Var> defArgs = def.getArgList();
ExprList subArgs = new ExprList();
for (int i = 0; i < args.size(); i++) {
Expr arg = args.get(i);
String var = arg.getVarName();
if (var == null) {
//Non-variable args may be passed as-is
subArgs.add(arg);
} else {
//We then use the arg as-is to substitute
if (i > defArgs.size())
throw new ExprBuildException("Unable to expand function dependency, the function <" + def.getUri() + "> is called but uses an argument ?" + var + " which is not an argument to the outer function");
subArgs.add(arg);
}
}
//Expand the function
uFunc.build(def.getUri(), subArgs);
return uFunc.getActualExpr();
} else {
return super.transform(func, args);
}
}
Aggregations