Skip to content

Commit

Permalink
refactor: update code style and syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
ashleycaselli committed Dec 18, 2024
1 parent 0845440 commit c3c258f
Show file tree
Hide file tree
Showing 21 changed files with 1,323 additions and 1,379 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,7 @@ public static Runnable register(Model model) {
FunctionRegistry.set(ARQ.getContext(), oldFR);
};
} else {
return () -> {
unregister(old);
};
return () -> unregister(old);
}
}

Expand Down
105 changes: 53 additions & 52 deletions src/main/java/org/topbraid/shacl/arq/functions/EvalExprPFunction.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
*/
package org.topbraid.shacl.arq.functions;

import java.net.URI;
import java.util.Iterator;

import org.apache.jena.graph.FrontsNode;
import org.apache.jena.graph.Node;
import org.apache.jena.query.Dataset;
import org.apache.jena.rdf.model.Model;
Expand All @@ -40,62 +38,65 @@
import org.topbraid.shacl.expr.NodeExpressionContext;
import org.topbraid.shacl.expr.NodeExpressionFactory;

import java.net.URI;
import java.util.Iterator;

/**
* The property function tosh:evalExpr.
* Binds the variable on the right hand side with all nodes produced by evaluating
* the given node expression against the given focus node
*
* (?expr ?focusNode) tosh:evalExpr ?result .
*
* <p>
* (?expr ?focusNode) tosh:evalExpr ?result .
*
* @author Holger Knublauch
*/
public class EvalExprPFunction extends PropertyFunctionBase {

@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());
@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(FrontsNode::asNode);

return new QueryIterExtendByVar(binding, (Var) argObject.getArg(), nit, execCxt);
}
return new QueryIterExtendByVar(binding, (Var) argObject.getArg(), nit, execCxt);
}
}
Loading

0 comments on commit c3c258f

Please sign in to comment.