use of org.apache.jena.reasoner.rulesys.Node_RuleVariable in project jena by apache.
the class BindingStack method getBinding.
/**
* If the node is a variable then return the current binding (null if not bound)
* otherwise return the node itself.
*/
public Node getBinding(Node node) {
if (node instanceof Node_RuleVariable) {
return environment[((Node_RuleVariable) node).getIndex()];
} else if (node instanceof Node_ANY) {
return null;
} else if (Functor.isFunctor(node)) {
Functor functor = (Functor) node.getLiteralValue();
if (functor.isGround())
return node;
Node[] args = functor.getArgs();
List<Node> boundargs = new ArrayList<>(args.length);
for (Node arg : args) {
Node binding = getBinding(arg);
if (binding == null) {
// Not sufficent bound to instantiate functor yet
return null;
}
boundargs.add(binding);
}
Functor newf = new Functor(functor.getName(), boundargs, functor.getImplementor());
return Functor.makeFunctorNode(newf);
} else {
return node;
}
}
use of org.apache.jena.reasoner.rulesys.Node_RuleVariable in project jena by apache.
the class GenericTripleMatchFrame method init.
/**
* Initialize the triple match to preserve the current context of the given
* LPInterpreter and search for the match defined by the current argument registers
* @param interpreter the interpreter instance whose env, trail and arg values are to be preserved
*/
@Override
public void init(LPInterpreter interpreter) {
super.init(interpreter);
Node s = LPInterpreter.deref(interpreter.argVars[0]);
subjectVar = (s instanceof Node_RuleVariable) ? (Node_RuleVariable) s : null;
Node p = LPInterpreter.deref(interpreter.argVars[1]);
predicateVar = (p instanceof Node_RuleVariable) ? (Node_RuleVariable) p : null;
Node o = LPInterpreter.deref(interpreter.argVars[2]);
objectVar = (o instanceof Node_RuleVariable) ? (Node_RuleVariable) o : null;
if (Functor.isFunctor(o)) {
objectFunctor = (Functor) o.getLiteralValue();
goal = new TriplePattern(s, p, null);
} else {
objectFunctor = null;
goal = new TriplePattern(s, p, o);
}
}
use of org.apache.jena.reasoner.rulesys.Node_RuleVariable in project jena by apache.
the class ConsumerChoicePointFrame method preserveState.
/**
* Preserve the state of an interpreter into this frame.
*/
public void preserveState(List<Node> trail) {
// Save the trail state
int trailLen = trail.size();
if (trailLen > trailLength) {
trailValues = new Node[trailLen];
trailVars = new Node_RuleVariable[trailLen];
}
trailLength = trailLen;
for (int i = 0; i < trailLen; i++) {
Node_RuleVariable var = (Node_RuleVariable) trail.get(i);
trailVars[i] = var;
trailValues[i] = var.getRawBoundValue();
}
// Save the permanent variables
Node[] currentPVars = envFrame.pVars;
if (currentPVars != null) {
if (pVars == null || pVars.length < currentPVars.length) {
pVars = new Node[currentPVars.length];
}
System.arraycopy(currentPVars, 0, pVars, 0, currentPVars.length);
}
}
Aggregations