com.hammurapi.reasoning.spi
Interface InferenceContext


public interface InferenceContext

Rule context

Author:
Pavel

Field Summary
static InferenceContext INSTANCE
          Implementations set this constant to provide rules access to inference context in implementation-neutral way.
 
Method Summary
 void addUndo(Runnable undoCommand)
          When an object is removed from knowledge base, its conclusions are also removed.
 boolean consumeInput(int position, boolean local)
          Rules invoke this method from multi-fact (multi-parameter) inference methods to indicate that a fact passed in position parameter shall not participate in further joins.
 boolean contains(Object fact)
           
 Collection<?> getObjects()
           
 Map<String,?> getProperties()
           
 int[] parameterIndices()
          This method shall be invoked only from accept methods.
 void post(Object... conclusions)
          Posts conclusions to rules container.
 void put(Object fact)
          Puts a fact to the knowledge base.
 void remove(Object fact)
          Removes object from the knowledge base.
 Method targetMethod()
           
 void update(Object fact)
          Updates mutable fact.
 void update(Object originalFact, Object newFact)
          Updates immutable fact with a new value.
 

Field Detail

INSTANCE

static final InferenceContext INSTANCE
Implementations set this constant to provide rules access to inference context in implementation-neutral way.

Method Detail

post

void post(Object... conclusions)
Posts conclusions to rules container. Objects placed to the knowledge base by this method are removed from the knowledge base when source facts are removed. Returning a value from inference method has the same effect.

Parameters:
conclusion -

put

void put(Object fact)
         throws ReasoningException
Puts a fact to the knowledge base. Objects placed to the knowledge base by this method remain in it even if source facts are removed.

Parameters:
fact -
Throws:
ReasoningException

consumeInput

boolean consumeInput(int position,
                     boolean local)
Rules invoke this method from multi-fact (multi-parameter) inference methods to indicate that a fact passed in position parameter shall not participate in further joins.

Parameters:
position -
local - Rule may consume incoming fact to prevent it being handled to other rules or to prevent its participation in further joins in multi-fact rules. If local is true, the fact is removed from further rule joins, but it will be handled to other rules. If false, the fact will not be handled to other rules, but it will be stored in rule's collection of input facts to participate in further joins.
Returns:
True if fact was successfully consumed. In multi-parameter joins fact may come from a rule collection, not from the engine's input. As such it might not be possible to prevent handling of the fact to other rules. In this case this method returns false.
Throws:
IllegalArgumentException - If local argument is true for single-parameter rules.

addUndo

void addUndo(Runnable undoCommand)
When an object is removed from knowledge base, its conclusions are also removed. If a rule needs to undo an action on object removal (e.g. delete a record from database, which was inserted on object addition), the rule shall register an undo handler.

Parameters:
fact - Fact to which the handler shall be attached.
undoCommand - Command which is executed when any of rule inputs is removed from the knowledge base.

parameterIndices

int[] parameterIndices()
This method shall be invoked only from accept methods.

Returns:
Parameter indices in the target method corresponding to accept method parameters.

targetMethod

Method targetMethod()
Returns:
Signature of the target multi-parameter infer() method.

contains

boolean contains(Object fact)
                 throws ReasoningException
Parameters:
fact - Fact.
Returns:
True if knowledge base contains given fact.
Throws:
ReasoningException

getObjects

Collection<?> getObjects()
                         throws ReasoningException
Returns:
Collection of all objects in the knowledge base.
Throws:
ReasoningException

getProperties

Map<String,?> getProperties()
                            throws ReasoningException
Returns:
Properties associated with rule session and given inference path.
Throws:
ReasoningException

remove

void remove(Object fact)
            throws ReasoningException
Removes object from the knowledge base.

Parameters:
fact -
Throws:
ReasoningException

update

void update(Object fact)
            throws ReasoningException
Updates mutable fact. Same as invoking update(fact, fact)

Parameters:
fact -
Throws:
ReasoningException

update

void update(Object originalFact,
            Object newFact)
            throws ReasoningException
Updates immutable fact with a new value.

Parameters:
originalFact - Original fact.
newFact - New fact to replace the original fact.
Throws:
ReasoningException