Java Code Examples for org.apache.jena.sparql.core.Substitute#substitute()
The following examples show how to use
org.apache.jena.sparql.core.Substitute#substitute() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TargetContainsPFunction.java From shacl with Apache License 2.0 | 6 votes |
@Override public QueryIterator exec(Binding binding, PropFuncArg argSubject, Node predicate, PropFuncArg argObject, ExecutionContext execCxt) { argSubject = Substitute.substitute(argSubject, binding); argObject = Substitute.substitute(argObject, binding); if(!argObject.getArg().isVariable()) { throw new ExprEvalException("Right hand side of tosh:targetContains must be a variable"); } Node targetNode = argSubject.getArgList().get(0); Node shapesGraphNode = argSubject.getArgList().get(1); Model currentModel = ModelFactory.createModelForGraph(execCxt.getActiveGraph()); Dataset dataset = new DatasetWithDifferentDefaultModel(currentModel, DatasetImpl.wrap(execCxt.getDataset())); Model model = dataset.getNamedModel(shapesGraphNode.getURI()); Resource target = (Resource) model.asRDFNode(targetNode); Set<Node> focusNodes = new HashSet<Node>(); SHACLUtil.addNodesInTarget(target, dataset, focusNodes); return new QueryIterExtendByVar(binding, (Var) argObject.getArg(), focusNodes.iterator(), execCxt); }
Example 2
Source File: ExtendedSubstitute.java From RDFstarTools with Apache License 2.0 | 5 votes |
public static Node substitute( Node n, Binding b ) { if ( n instanceof Node_Triple ) { final Triple t1 = ((Node_Triple) n).get(); final Triple t2 = substitute(t1, b); if ( t1 == t2 ) return n; else return new Node_TripleStarPattern(t2); } else return Substitute.substitute(n, b); }
Example 3
Source File: GenerateFormPlan.java From sparql-generate with Apache License 2.0 | 5 votes |
private void substAndOutputForList( final Node subject, final Node predicate, final Node_List list, final StringBuilder sb, final Binding binding, final StreamRDF outputStream, final Context context, final int position, final Map<Node, Node> bNodeMap) { final Node first = ContextUtils.getNode(context, list, 0); final Node current = ContextUtils.getNode(context, list, position); final Node next = ContextUtils.getNode(context, list, position + 1); final Node var = list.getExpr().asVar(); // potentially substitute subject and predicate Node s2 = subst(subject, bNodeMap); Node p2 = subst(predicate, bNodeMap); Triple t = new Triple(s2, p2, first); Triple t2 = Substitute.substitute(t, binding); outputIfConcrete(sb, outputStream, t2); // potentially substitute var Node var2 = subst(var, bNodeMap); Node var2sub = Substitute.substitute(var2, binding); Triple tfirst = new Triple(current, FIRST, var2sub); outputIfConcrete(sb, outputStream, tfirst); // nothing to substitute here Triple tRest = new Triple(current, REST, next); outputIfConcrete(sb, outputStream, tRest); }
Example 4
Source File: EvalExprPFunction.java From shacl with Apache License 2.0 | 4 votes |
@Override public QueryIterator exec(Binding binding, PropFuncArg argSubject, Node predicate, PropFuncArg argObject, ExecutionContext execCxt) { argSubject = Substitute.substitute(argSubject, binding); argObject = Substitute.substitute(argObject, binding); if(!argObject.getArg().isVariable()) { throw new ExprEvalException("Right hand side of tosh:exprEval must be a variable"); } Node exprNode = argSubject.getArgList().get(0); Node focusNode = argSubject.getArgList().get(1); Model model = ModelFactory.createModelForGraph(execCxt.getActiveGraph()); Dataset dataset = ARQFactory.get().getDataset(model); URI shapesGraphURI = URI.create("urn:x-topbraid:dummyShapesGraph"); dataset.addNamedModel(shapesGraphURI.toString(), model); ShapesGraph[] shapesGraph = new ShapesGraph[1]; NodeExpression n = NodeExpressionFactory.get().create(model.asRDFNode(exprNode)); ExtendedIterator<RDFNode> it = n.eval(model.asRDFNode(focusNode), new NodeExpressionContext() { @Override public URI getShapesGraphURI() { return shapesGraphURI; } @Override public ShapesGraph getShapesGraph() { if(shapesGraph[0] == null) { shapesGraph[0] = new ShapesGraph(model); } return shapesGraph[0]; } @Override public Dataset getDataset() { return dataset; } }); Iterator<Node> nit = it.mapWith(rdfNode -> rdfNode.asNode()); return new QueryIterExtendByVar(binding, (Var) argObject.getArg(), nit, execCxt); }