Algernon Software

org.algernon.rule
Class RuleManager

java.lang.Object
  extended byorg.jatha.dynatype.StandardLispValue
      extended byorg.algernon.rule.RuleManager
All Implemented Interfaces:
Comparable, LispValue

public class RuleManager
extends StandardLispValue

The RuleManager manages rules in Algernon. It stores and retrieves rules and continuations.


Field Summary
static int BACKWARD_CHAIN
           
(package private)  Algernon f_algy
           
static int FORWARD_CHAIN
           
static int FRAME_RULE
           
protected static int INITIAL_LIST_SIZE
           
protected static int LARGE_INITIAL_HASH_SIZE
           
(package private)  HashMap m_allRules
           
(package private)  HashMap m_frameBCRules
           
(package private)  HashMap m_frameFCRules
           
(package private)  HashMap m_frameParents
           
(package private)  HashMap m_slotBCRules
           
(package private)  HashMap m_slotFCRules
           
static int SLOT_RULE
           
protected static int SMALL_INITIAL_HASH_SIZE
           
 
Fields inherited from class org.jatha.dynatype.StandardLispValue
f_lisp
 
Constructor Summary
RuleManager(Algernon algy)
          Create a new Algernon Rule
 
Method Summary
 void addClosure(Closure closure)
          Adds a closure to the system.
 void addRule(Rule rule)
          Stores one rule of the given direction and type.
 void addRule(Rule rule, AlgernonFrame associatedFrame)
          Stores one rule of the given direction and type, associated with the given frame (which should be a class or slot, as appropriate.
 void clear()
          Removes all rules and rule continuations.
 String continuationRuleName(Rule rule, int index)
          Returns a string containing the name of a continuation rule.
 Collection getAllRules()
          Returns a Collection of all rules.
(package private)  Collection getParents(AlgernonFrame frame)
          Returns a list of the parents of a frame.
 Rule getRule(String ruleName)
          Looks up a rule by its name.
 Collection getRules(AlgernonFrame frame, int direction, int type)
          Retrieves a collection of Closures that are associated with the given frame.
 Iterator ruleNameIterator()
          An iterator that iterates over the names of all the rules in the system.
 Collection searchForRules(String str)
          Returns all rules with the given string in their names.
 
Methods inherited from class org.jatha.dynatype.StandardLispValue
abs, acos, add, adjustSpecialCount, append, apply, apropos_print, asin, assoc, atan, atan2, atom, basic_atom, basic_bignump, basic_consp, basic_constantp, basic_floatp, basic_foreignp, basic_functionp, basic_integerp, basic_keywordp, basic_length, basic_listp, basic_macrop, basic_null, basic_numberp, basic_stringp, basic_symbolp, bignump, boundp, butlast, car, cdr, ceiling, characterp, clrhash, compareTo, concatenate, consp, constantp, contains, copy_list, copy, cos, cot, csc, degreesToRadians, divide, eighth, elt, elt, eq, eql, equal, equalNumeric, factorial, fboundp, fifth, first, floatp, floor, fourth, funcall, functionp, get_specialCount, gethash, gethash, getLisp, greaterThan, greaterThanOrEqual, hash_table_count, hash_table_rehash_size, hash_table_rehash_threshold, hash_table_size, hash_table_test, hashtablep, integerp, internal_getName, internal_prin1_as_cdr, internal_prin1, internal_princ_as_cdr, internal_princ, internal_print_as_cdr, internal_print, iterator, keywordp, last, length, lessThan, lessThanOrEqual, lisp_null, list, listp, max, member, min, multiply, nconc, negate, neql, ninth, nreverse, nstringCapitalize, nstringDowncase, nstringUpcase, numberp, pop, position, prin1, princ, print, push, radiansToDegrees, rassoc, reciprocal, remhash, remove, rest, reverse, rplaca, rplacd, sec, second, set_special, setf_gethash, setf_symbol_function, setf_symbol_plist, setf_symbol_value, setLisp, setPackage, setq, seventh, sin, sixth, specialP, sqrt, string, stringCapitalize, stringDowncase, stringEndsWith, stringEq, stringEqual, stringGreaterP, stringGreaterThan, stringGreaterThanOrEqual, stringLeftTrim, stringLeftTrim, stringLessP, stringLessThan, stringLessThanOrEqual, stringNeq, stringNotGreaterP, stringNotLessP, stringp, stringRightTrim, stringRightTrim, stringStartsWith, stringTrim, stringTrim, stringUpcase, subst, substring, substring, subtract, symbol_function, symbol_name, symbol_package, symbol_plist, symbol_value, symbolp, tan, tenth, third, toCollection, toJava, toJava, toString, toString, toStringAsCdr_internal, toStringAsCdr, toStringShort, toStringShort, toStringSimple, type_of, typep, zerop
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

BACKWARD_CHAIN

public static int BACKWARD_CHAIN

FORWARD_CHAIN

public static int FORWARD_CHAIN

FRAME_RULE

public static int FRAME_RULE

SLOT_RULE

public static int SLOT_RULE

SMALL_INITIAL_HASH_SIZE

protected static int SMALL_INITIAL_HASH_SIZE

LARGE_INITIAL_HASH_SIZE

protected static int LARGE_INITIAL_HASH_SIZE

INITIAL_LIST_SIZE

protected static int INITIAL_LIST_SIZE

f_algy

Algernon f_algy

m_allRules

HashMap m_allRules

m_frameParents

HashMap m_frameParents

m_frameFCRules

HashMap m_frameFCRules

m_frameBCRules

HashMap m_frameBCRules

m_slotFCRules

HashMap m_slotFCRules

m_slotBCRules

HashMap m_slotBCRules
Constructor Detail

RuleManager

public RuleManager(Algernon algy)
Create a new Algernon Rule

Method Detail

clear

public void clear()
Removes all rules and rule continuations. Does not remove new facts inferred by the rules. Retains the frameParents hash table.


continuationRuleName

public String continuationRuleName(Rule rule,
                                   int index)
Returns a string containing the name of a continuation rule.


searchForRules

public Collection searchForRules(String str)
Returns all rules with the given string in their names.


getRule

public Rule getRule(String ruleName)
Looks up a rule by its name.


getParents

Collection getParents(AlgernonFrame frame)
Returns a list of the parents of a frame. For an instance, this is its class and all of the superclasses of the class, all the way to the root class. For a class, this is all of its parents up to the root class.


addRule

public void addRule(Rule rule)
Stores one rule of the given direction and type. Does not store any closures. The rule will not be activated until closures for it are created and stored.


addRule

public void addRule(Rule rule,
                    AlgernonFrame associatedFrame)
Stores one rule of the given direction and type, associated with the given frame (which should be a class or slot, as appropriate.


addClosure

public void addClosure(Closure closure)
Adds a closure to the system. A closure is a rule plus bindings.


getAllRules

public Collection getAllRules()
Returns a Collection of all rules.


getRules

public Collection getRules(AlgernonFrame frame,
                           int direction,
                           int type)
Retrieves a collection of Closures that are associated with the given frame. FRAME-related or SLOT-related rules can be retrieved, and FORWARD or BACKWARD-chaining rules can also be retrieved.


ruleNameIterator

public Iterator ruleNameIterator()
An iterator that iterates over the names of all the rules in the system. Objects returned are Strings. Use getRule(name) to get the Rule.


Algernon Software