jdrew.oo.bu
Class ForwardReasoner

java.lang.Object
  extended by jdrew.oo.bu.ForwardReasoner

public class ForwardReasoner
extends java.lang.Object

This class implements the forward reasoner (bottom-up) modules of OO jDREW; The unifier for this module is implemented by the jdrew.oo.bu.Unifier class and a subsumption checking system is implemented by the jdrew.oo.bu.Subsumption Class. A forward reasoner works by processing "new" facts; As each new fact is processed unificiation with all previously exisiting rules is attempted; if the unification is successful one of two things happens: if the resolvent is a fact then it is added to the end of the new facts list; if the resolvent is a rule then it is processed (attempting unification with all processed facts) and is then added to the list of rules.

Title: OO jDREW

Description: Reasoning Engine for the Semantic Web - Supporting OO RuleML 0.88

Copyright: Copyright (c) 2005

Version:
0.89
Author:
Marcel A. Ball

Field Summary
static int rem
           
 
Constructor Summary
ForwardReasoner()
          This method constructs a new ForwardReasoner object (implementation of a bottom-up reasoning engine); creating the required buffers for knowledge base storage (oldFacts and rules Hashtable's and newFacts Vector) and registers the system provided built-in relations with the engine by calling the registerBuiltins();
 
Method Summary
 void buildPrecedenceGraph()
          This method builds a precedence graph based on the given rules.
 boolean detectNegativeCycle()
          This method is used to see if there is a negative edge in a cycle in the precedence graph.
 int getLoopCounter()
          This method is used to get the number of times when the forward reasoner should stop running.
 java.util.Vector getMessage()
          This method returns a vector of strings containing information about stratification.
 java.util.Vector getNewFacts()
          Allows user code to access the newFacts vector.
 java.util.Hashtable getOldFacts()
          Allows user code to access the oldFacts hash table.
 java.util.Hashtable getRules()
          Allows user code to access the rules hash table.
 boolean isStratifiable()
          This method is used to see if a Knowledge base is statfiable or not.
 void loadClauses(java.util.Iterator it)
          This method is used to load clauses into the reasoning engine.
 java.lang.String printClauses(int type, int format)
          This method will return a string that will contain the new facts and old facts in ruleML or posl form If type is equal to true then it will display in posl If type is equal to false then it will display ruleml
 void registerBuiltin(BUBuiltin b)
          This method is used to register a new user created built-in with the reasoning engine.
 void registerBuiltin(Builtin b)
          This method is used to register a new user created built-in with the reasoning engine.
 boolean rulesContainsNaf()
          This method is used to see if the body of any rule contains a naf to see whether or not we need to check for stratification.
 void runForwardReasoner()
          This method runs the main forward reasoner; causing the engine to find all possible conclusions from the knowledge base that was loaded into the engine.
 void setLoopCounter(int number)
          This method is used to set the number of times when the forward reasoner should stop running.
 void setLoopCounter(java.lang.String number)
          This method is used to set the number of times when the forward reasoner should stop running.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

rem

public static int rem
Constructor Detail

ForwardReasoner

public ForwardReasoner()
This method constructs a new ForwardReasoner object (implementation of a bottom-up reasoning engine); creating the required buffers for knowledge base storage (oldFacts and rules Hashtable's and newFacts Vector) and registers the system provided built-in relations with the engine by calling the registerBuiltins();

Method Detail

getNewFacts

public java.util.Vector getNewFacts()
Allows user code to access the newFacts vector. Users may want to use this in their code to allow the display of information in the knowledge base.

Returns:
Vector A reference to the newFacts Vector for this bottom-up reasoning engine.

getOldFacts

public java.util.Hashtable getOldFacts()
Allows user code to access the oldFacts hash table. Users may want to use this in their code to allow the display of information in the knowledge base.

Returns:
Hashtable A reference to the oldFacts Hashtable for this bottom-up reasoning engine.

getRules

public java.util.Hashtable getRules()
Allows user code to access the rules hash table. Users may want to use this in their code to allow the display of information in the knowledge base.

Returns:
Hashtable A reference to the oldFacts Hashtable for this bottom-up reasoning engine.

registerBuiltin

public void registerBuiltin(Builtin b)
This method is used to register a new user created built-in with the reasoning engine. This version of the method is for those built-ins that implement the jdrew.oo.builtins.Builtin interface (these can be used with both the bottom-up and the top-down engine). If the built-in that is being created requires access to the data structures of the reasoning engine it should instead extend the jdrew.oo.bu.builtins.BUBuiltin class and be registered with the registerBuiltin(BUBuiltin) method.

Parameters:
b - Builtin An instance of the class that implements the built-in relation; this should implement the jdrew.oo.builtins.Builtin interface.

registerBuiltin

public void registerBuiltin(BUBuiltin b)
This method is used to register a new user created built-in with the reasoning engine. This version of the method is for those built-ins that extend the jdrew.oo.bu.builtins.BUBuiltin class (those specific to the bottom-up engine).

Parameters:
b - BUBuiltin An instance of the class that implements the built-in relation; this should be a sub-class of the jdrew.oo.bu.builtins.BUBuiltin class.

printClauses

public java.lang.String printClauses(int type,
                                     int format)
This method will return a string that will contain the new facts and old facts in ruleML or posl form If type is equal to true then it will display in posl If type is equal to false then it will display ruleml


loadClauses

public void loadClauses(java.util.Iterator it)
This method is used to load clauses into the reasoning engine. This will process each clause as it is loaded - placing new facts into the new facts list and processing new rules against all exisiting processed facts.

Parameters:
it - Iterator An iterator containing the new clauses to be loaded; this should only iterate over DefiniteClause objects. These iterators can be created by calling the iterator() method of parsers - such as RuleMLParser or POSLParser.

runForwardReasoner

public void runForwardReasoner()
This method runs the main forward reasoner; causing the engine to find all possible conclusions from the knowledge base that was loaded into the engine. Bellow is the main process of the system. As long as there is a new fact in the newFacts list remove the first fact from the list. Check to see if this fact is subsumed by another already processed fact (oldFacts); if it is subsumed, discard the fact and move to the next fact in the list. Add the fact to the old fact table. Find all rules that may be possible unification matches with the newly selected fact. Attempt unification with each possible rule; if the unification succeeds then build the resolvent and call the process(DefiniteClause) method passing the newly created resolvent.


buildPrecedenceGraph

public void buildPrecedenceGraph()
This method builds a precedence graph based on the given rules. For each rule we must find the head of the rule and then check if it exists or not. If it exists we use that node as the sink for each body term. If it doesn't exists we make a new node object with the term object and it is used for the sink of each body term. We test if a term exists or not by unifying the head of the rule with all the other terms that we seen already. If we create a node we have to store it in the node vector, that is used to compare if a node exists or not. Then for each body clause of a rule we check if the term already exists or not. If it doesn't we create a new node with the term object for the source. If it does exist we just use that node as the source. If we create a node we have to store it in the node vector, that is used to compare if a node exists or not. After we get a source and a sink node we can then create a edge. The edges are what define the graph. For every head of a rule and each body clause there will be an edge created. See the source for a more detailed comment.


detectNegativeCycle

public boolean detectNegativeCycle()
This method is used to see if there is a negative edge in a cycle in the precedence graph. What it does is check every edge in the predence graph and test if it is within a cycle and if it is then we test if the edge is negative. If we find a negative edge in a cycle its all we need to know that a knowledge base is not stratfiable. We loop through each edge and check if its source and sink are nodes in cycles, which ptolemy can detect. So we loop through all possible combinations of cycle nodes and see if the edge exists or not It also populates a string vector containing the reasons why stratification fails.

Returns:
boolean - true if a negative edge exists, false otherwise

isStratifiable

public boolean isStratifiable()
This method is used to see if a Knowledge base is statfiable or not. It first checks if the rules contain a naf or not. If no rule contains a naf then its stratfiable. If there is a naf we have to create a precedence graph and test if there is a negative cycle or not.

Returns:
boolean - true if the knowledge base is stratfiable, false otherwise

rulesContainsNaf

public boolean rulesContainsNaf()
This method is used to see if the body of any rule contains a naf to see whether or not we need to check for stratification. It goes through each rule to see if a term contains a naf or not. If no rules contain a naf then we know its stratifiable and there is no point in building a precedence graph and checking for negative cycles.

Returns:
boolean - true if a rule contians naf, false otherwise

setLoopCounter

public void setLoopCounter(java.lang.String number)
This method is used to set the number of times when the forward reasoner should stop running.

Parameters:
String - - the number of times a rule should loop

setLoopCounter

public void setLoopCounter(int number)
This method is used to set the number of times when the forward reasoner should stop running.

Parameters:
int - - the number of times a rule should loop

getLoopCounter

public int getLoopCounter()
This method is used to get the number of times when the forward reasoner should stop running.

Returns:
int - the number of times a rule should loop

getMessage

public java.util.Vector getMessage()
This method returns a vector of strings containing information about stratification.

Returns:
vector - a vector of strings containing why stratification fails