Class BindingVector
- java.lang.Object
-
- org.apache.jena.reasoner.rulesys.impl.BindingVector
-
- All Implemented Interfaces:
BindingEnvironment
public class BindingVector extends java.lang.Object implements BindingEnvironment
An implementation of a binding environment that maintains a single array of bound values for the variables in a rule. Stack management is done externally. This is intended for use in the Brule system and so also supports variable-variable bindings by use of reference chains.
-
-
Constructor Summary
Constructors Constructor Description BindingVector(int size)
Constructor - create an empty binding environmentBindingVector(Node[] env)
Constructor - create a binding environment from a vector of bindingsBindingVector(BindingVector clone)
Constructor - create a binding environment which is a copy of the given environment
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
bind(int i, Node value)
Bind the ith variable in the current environment to the given value.boolean
bind(Node var, Node value)
Bind a variable in the current environment to the given value.boolean
equals(java.lang.Object o)
Equality overrideNode
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 bindings.Node
getGroundVersion(Node node)
Return the most ground version of the node.int
hashCode()
hash function overrideTriple
instantiate(TriplePattern pattern)
Instantiate a triple pattern against the current environment.TriplePattern
partInstantiate(TriplePattern goal)
Bind the variables in a goal pattern using the binding environment, to generate a more specialized goaljava.lang.String
toString()
Printable formstatic BindingVector
unify(TriplePattern goal, TriplePattern head, int numRuleVars)
Unify a goal with the head of a rule.
-
-
-
Constructor Detail
-
BindingVector
public BindingVector(int size)
Constructor - create an empty binding environment
-
BindingVector
public BindingVector(Node[] env)
Constructor - create a binding environment from a vector of bindings
-
BindingVector
public BindingVector(BindingVector clone)
Constructor - create a binding environment which is a copy of the given environment
-
-
Method Detail
-
getEnvironment
public Node[] getEnvironment()
Return the current array of bindings. Useful for fast access to several bindings, not useful for doing updates.
-
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 environment to the given value. Checks that the new binding is compatible with any current binding. Handles aliased variables.- Returns:
- false if the binding fails
-
bind
public boolean bind(Node var, Node value)
Bind a variable in the current environment 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
-
partInstantiate
public TriplePattern partInstantiate(TriplePattern goal)
Bind the variables in a goal pattern using the binding environment, to generate a more specialized goal- Parameters:
goal
- the TriplePattern to be instantiated- Returns:
- a TriplePattern obtained from the goal by substituting current bindings
-
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
-
toString
public java.lang.String toString()
Printable form- Overrides:
toString
in classjava.lang.Object
-
unify
public static BindingVector unify(TriplePattern goal, TriplePattern head, int numRuleVars)
Unify a goal with the head of a rule. This is a poor-man's unification, we should try switching to a more conventional global-variables-with-trail implementation in the future.- Parameters:
goal
- the goal pattern which it being matched to a rulehead
- the head pattern of the rule which is being instantiatednumRuleVars
- the length of the environment to allocate.- Returns:
- An initialized binding environment for the rule variables or null if the unification fails. If a variable in the environment becomes aliased to another variable through the unification this is represented by having its value in the environment be the variable to which it is aliased.
-
equals
public boolean equals(java.lang.Object o)
Equality override- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
hash function override- Overrides:
hashCode
in classjava.lang.Object
-
-