Class 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 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 interface BindingEnvironment
      • 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 interface BindingEnvironment
        Parameters:
        var - a Node_RuleVariable defining the variable to bind
        value - 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 interface BindingEnvironment
        Parameters:
        pattern - the triple pattern to match
        Returns:
        a new, instantiated triple
      • toString

        public java.lang.String toString()
        Printable form
        Overrides:
        toString in class java.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 rule
        head - the head pattern of the rule which is being instantiated
        numRuleVars - 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 class java.lang.Object
      • hashCode

        public int hashCode()
        hash function override
        Overrides:
        hashCode in class java.lang.Object