Class BFRuleContext

  • All Implemented Interfaces:
    RuleContext

    public class BFRuleContext
    extends java.lang.Object
    implements RuleContext
    An implementation of the generic RuleContext interface used by the basic forward (BF) rule engine. This provides additional methods specific to the functioning of that engine.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void add​(Triple t)
      Add a triple to a temporary "pending" store, ready to be added to added to the deductions graph and the processing stack later.
      void addTriple​(Triple t)
      Add a triple to the stack of triples to waiting to be processed by the rule engine.
      boolean contains​(Node s, Node p, Node o)
      Return true if the triple pattern is already in either the graph or the stack.
      boolean contains​(Triple t)
      Return true if the triple is already in either the graph or the stack.
      ClosableIterator<Triple> find​(Node s, Node p, Node o)
      In some formulations the context includes deductions that are not yet visible to the underlying graph but need to be checked for.
      void flushPending()
      Take all the pending triples and add them to both the given graph and to the processing stack.
      BindingEnvironment getEnv()
      Returns the current variable binding environment for the current rule.
      BindingStack getEnvStack()
      Variant of the generic getEnv interface specific to the basic forward rule system.
      InfGraph getGraph()
      Returns the graph.
      Triple getNextTriple()
      Return the next triple to be added to the graph, removing it from the stack.
      Rule getRule()
      Returns the rule.
      void remove​(Triple t)
      Remove a triple from the deduction graph (and the original graph if relevant).
      void resetEnv​(int newSize)
      Reset the binding environment back to empty.
      void setRule​(Rule rule)
      Sets the rule.
      void silentAdd​(Triple t)
      Assert a new triple in the deduction graph, bypassing any processing machinery.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • BFRuleContext

        public BFRuleContext​(ForwardRuleInfGraphI graph)
        Constructor.
        Parameters:
        graph - the inference graph which owns this context.
    • Method Detail

      • getEnv

        public BindingEnvironment getEnv()
        Returns the current variable binding environment for the current rule.
        Specified by:
        getEnv in interface RuleContext
        Returns:
        BindingEnvironment
      • getEnvStack

        public BindingStack getEnvStack()
        Variant of the generic getEnv interface specific to the basic forward rule system. Returns the current variable binding environment for the current rule.
        Returns:
        BindingStack
      • getRule

        public Rule getRule()
        Returns the rule.
        Specified by:
        getRule in interface RuleContext
        Returns:
        Rule
      • setRule

        public void setRule​(Rule rule)
        Sets the rule.
        Specified by:
        setRule in interface RuleContext
        Parameters:
        rule - The rule to set
      • addTriple

        public void addTriple​(Triple t)
        Add a triple to the stack of triples to waiting to be processed by the rule engine.
      • add

        public void add​(Triple t)
        Add a triple to a temporary "pending" store, ready to be added to added to the deductions graph and the processing stack later.

        This is needed to prevent concurrent modification exceptions which searching the deductions for matches to a given rule.

        Specified by:
        add in interface RuleContext
      • flushPending

        public void flushPending()
        Take all the pending triples and add them to both the given graph and to the processing stack.
      • contains

        public boolean contains​(Triple t)
        Return true if the triple is already in either the graph or the stack. I.e. it has already been deduced.
        Specified by:
        contains in interface RuleContext
      • contains

        public boolean contains​(Node s,
                                Node p,
                                Node o)
        Return true if the triple pattern is already in either the graph or the stack. I.e. it has already been deduced.
        Specified by:
        contains in interface RuleContext
      • find

        public ClosableIterator<Triple> find​(Node s,
                                             Node p,
                                             Node o)
        In some formulations the context includes deductions that are not yet visible to the underlying graph but need to be checked for. However, currently this calls the graph find directly.
        Specified by:
        find in interface RuleContext
      • getNextTriple

        public Triple getNextTriple()
        Return the next triple to be added to the graph, removing it from the stack.
        Returns:
        the Triple or null if there are no more
      • resetEnv

        public void resetEnv​(int newSize)
        Reset the binding environment back to empty.
        Parameters:
        newSize - the number of variables needed for processing the new rule
      • silentAdd

        public void silentAdd​(Triple t)
        Assert a new triple in the deduction graph, bypassing any processing machinery.
        Specified by:
        silentAdd in interface RuleContext
      • remove

        public void remove​(Triple t)
        Remove a triple from the deduction graph (and the original graph if relevant).
        Specified by:
        remove in interface RuleContext