Inference Engine
The Engine provides the main Expert System functions, such as chaining and inference.
Synopsis
use Pie::Engine;
$engine = Pie::Engine->new();Constructor
The Engine object can be constructed with the Knowledge Base object and an optional associative array of options as arguments. The options are:
- attributes
This defines the implementation of the attribute store within the Engine. It defaults to 'Memory'.
mixed_mode
Switches the engine into Mixed Mode or Traditional Mode chaining (particularly when back chaining). Traditional Mode uses only traditional back chaining, where as Mixed Mode employs "mini" forward chains whilst back chaining. Returns the old mode (0 = traditional, 1 = mixed mode), an optionally takes an argument to set the mode.
set_attribute
Sets an attribute. This method can be used to set an attribute before performing chaining. Requires an attribute name and value as arguments, as well as an optional confidence value (in the range 0 to 1). Attribute names are strings, and have to be unique across the engine. Attributes are stored as Attribute objects; this object will be created if it does not exist.
If the engine is in mixed mode, setting an attribute also performs a mini-forward chain to evaluate any rules that may have become solvable.
check_attribute
Checks if the supplied attribute has been set, returns 1 if it has, or 0 if not.
unset_attribute
Unsets the supplied attribute. This leaves the attribute in an unset state, but still created. That is, check_attribute() would return 1 for it, but the attribute's value will be "undef".
get_attribute
Returns the Attribute object for the supplied attribute.
forward_chain
Performs a forward chain on the known attributes. This process infers new attributes by evaluating rules from the rule set. New attributes are set automatically, and so can be interrogated after chaining is complete.
solve_with_attribute
This is mainly an internal function. It attempts to forward chain from a given attribute. That is, it (re)evaluates all the rules that have the given attribute as a condition. Mostly used internally when Mixed Mode is on.
mixed_chain
This is a helper function designed to solve for as many cases as possible before working on the supplied goal attribute. It performs a full forward chain, and then uses mixed mode backward chaining (regadless of the setting of mixed_mode()). It returns the same as back_chain().
back_chain
Requires a goal attribute to be supplied. Back chaining attempts to solve for the goal attribute by asking questions to obtain the value of any attributes that are required.
back_chain() returns a string, which will be one of "solved", "unsolvable" or "failed", indicating what happened during chaining.
show_working
Returns a list of reasons why the supplied attribute was set as it is. The list returned is a list of references to associative arrays that contain the elements "rule" (the rule's name) and "reasons" which is a list of Attribute objects that were used to set the rule.
