Class BindingStack
- java.lang.Object
-
- org.apache.jena.reasoner.rulesys.impl.BindingStack
-
- All Implemented Interfaces:
BindingEnvironment
public class BindingStack extends java.lang.Object implements BindingEnvironment
Provides a trail of possible variable bindings for a forward rule.
-
-
Constructor Summary
Constructors Constructor Description BindingStack()
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
bind(int i, Node value)
Bind the ith variable in the current envionment to the given value.boolean
bind(Node var, Node value)
Bind a variable in the current envionment to the given value.void
bindNoCheck(Node_RuleVariable var, Node value)
Bind a variable in the current envionment to the given value.void
commit()
Forget the previously pushed state but keep the current environment.Node
getBinding(Node node)
If the node is a variable then return the current binding (null if not bound) otherwise return the node itself.Node[]
getEnvironment()
Return the current array of bindingsNode
getGroundVersion(Node node)
Return the most ground version of the node.Triple
instantiate(TriplePattern pattern)
Instantiate a triple pattern against the current environment.void
push()
Save the current environment on an internal stackvoid
reset(int newSize)
Reset the binding environment to empty.void
unwind()
Forget the current environment and return the previously pushed state.
-
-
-
Method Detail
-
push
public void push()
Save the current environment on an internal stack
-
unwind
public void unwind() throws java.lang.IndexOutOfBoundsException
Forget the current environment and return the previously pushed state.- Throws:
java.lang.IndexOutOfBoundsException
- if there was not previous push
-
commit
public void commit() throws java.lang.IndexOutOfBoundsException
Forget the previously pushed state but keep the current environment.- Throws:
java.lang.IndexOutOfBoundsException
- if there was not previous push
-
reset
public void reset(int newSize)
Reset the binding environment to empty.- Parameters:
newSize
- the number of variables needed for processing the new rule
-
getEnvironment
public Node[] getEnvironment()
Return the current array of bindings
-
getBinding
public Node getBinding(Node node)
If the node is a variable then return the current binding (null if not bound) otherwise return the node itself.
-
getGroundVersion
public Node getGroundVersion(Node node)
Return the most ground version of the node. If the node is not a variable just return it, if it is a variable bound in this environment return the binding, if it is an unbound variable return the variable.- Specified by:
getGroundVersion
in interfaceBindingEnvironment
-
bind
public boolean bind(int i, Node value)
Bind the ith variable in the current envionment to the given value. Checks that the new binding is compatible with any current binding.- Returns:
- false if the binding fails
-
bind
public boolean bind(Node var, Node value)
Bind a variable in the current envionment to the given value. Checks that the new binding is compatible with any current binding.- Specified by:
bind
in interfaceBindingEnvironment
- Parameters:
var
- a Node_RuleVariable defining the variable to bindvalue
- the value to bind- Returns:
- false if the binding fails
-
bindNoCheck
public void bindNoCheck(Node_RuleVariable var, Node value)
Bind a variable in the current envionment to the given value. Overrides and ignores any current binding.- Parameters:
var
- a Node_RuleVariable defining the variable to bindvalue
- the value to bind
-
instantiate
public Triple instantiate(TriplePattern pattern)
Instantiate a triple pattern against the current environment. This version handles unbound variables by turning them into bNodes.- Specified by:
instantiate
in interfaceBindingEnvironment
- Parameters:
pattern
- the triple pattern to match- Returns:
- a new, instantiated triple
-
-