biz.hammurapi.rules
Class Conclusion

java.lang.Object
  extended by biz.hammurapi.rules.Conclusion
All Implemented Interfaces:
Negatable, Supercedable, biz.hammurapi.swing.Visualizable, biz.hammurapi.xml.dom.DomSerializable, java.io.Serializable
Direct Known Subclasses:
SimpleConclusion

public class Conclusion
extends java.lang.Object
implements biz.hammurapi.xml.dom.DomSerializable, java.io.Serializable, biz.hammurapi.swing.Visualizable, Negatable, Supercedable

Base class for conclusions.

Author:
Pavel Vlasov
See Also:
Serialized Form

Field Summary
protected  java.util.HashMap slots
          Slots (other facts) belonging to this fact.
 
Constructor Summary
  Conclusion()
          Default constructor
protected Conclusion(java.lang.String pattern)
           
 
Method Summary
 void addDerivation(Derivation derivation)
          Adds a derivation to conclusion.
 boolean equals(java.lang.Object obj)
           
 int getCardinality()
           
 int getDepth()
           
 java.util.Set getDerivations()
          It is possible to come to the same conclusion through multiple inference paths.
protected  java.lang.Object getSlot(java.lang.String name)
          Returns slot value
 int hashCode()
           
 boolean isDerivedFrom(java.lang.Object fact)
           
 boolean isNegatedBy(Negator negator)
          Returns true if negator negates this conclusion any of its slots or all its derivations.
 void mergeDerivations(Conclusion otherConclusion)
          Merges derivations of two equal conclusions.
static boolean object2Negator(java.lang.Object o, Negator n)
          Convenience method to properly negate objects taking implementations of Negatable into account.
protected  void setSlot(java.lang.String slotName, java.lang.Object value)
          Puts value to a slot.
 boolean supercedes(java.lang.Object obj)
          One conclusion supercedes another if it is a subclass of the other and slots of the both are equal.
 void toDom(org.w3c.dom.Element holder)
           
 java.lang.String toString()
          If pattern is null then outputs class name and list of slots and their values, otherwise formats pattern.
 javax.swing.tree.TreeNode toTreeNode(javax.swing.tree.TreeNode parent, java.lang.String title)
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

slots

protected java.util.HashMap slots
Slots (other facts) belonging to this fact.

Constructor Detail

Conclusion

protected Conclusion(java.lang.String pattern)
Parameters:
pattern - Pattern to use in toString(). The pattern should use ${slot name} placeholders. E.g. Parent conclusion can use pattern "${parent} is parent of ${child}".

Conclusion

public Conclusion()
Default constructor

Method Detail

setSlot

protected void setSlot(java.lang.String slotName,
                       java.lang.Object value)
Puts value to a slot. Value gets converted to a handle.

Parameters:
slotName -
value -

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object

mergeDerivations

public void mergeDerivations(Conclusion otherConclusion)
Merges derivations of two equal conclusions. This is useful when two there are two paths to the same conclusion.

Parameters:
otherConclusion -

supercedes

public boolean supercedes(java.lang.Object obj)
One conclusion supercedes another if it is a subclass of the other and slots of the both are equal. In other words more specific conclusion supercedec more generic. E.g. conclusion that Mary is a mother of Joe is more specific than that Mary is a parent of Joe.

Specified by:
supercedes in interface Supercedable
Parameters:
conclusion -
Returns:
true if this fact is more specific than argument.

getDerivations

public java.util.Set getDerivations()
It is possible to come to the same conclusion through multiple inference paths.

Returns:
Set of derivations.

getCardinality

public int getCardinality()
Returns:
number of derivations.

getDepth

public int getDepth()
Returns:
minimum derivation depth, in other words shortest logical chain which led to this conclusion.

toDom

public void toDom(org.w3c.dom.Element holder)
Specified by:
toDom in interface biz.hammurapi.xml.dom.DomSerializable

isNegatedBy

public boolean isNegatedBy(Negator negator)
Returns true if negator negates this conclusion any of its slots or all its derivations. If conclusion has more than one derivation that negated derivations are removed from derivations collection. Conclusion is negated based on derivations only if at leas one of its derivations is negated. In other words conclusion which collection of derivations is empty will not be negated based on derivations but only based on self and slots.

Specified by:
isNegatedBy in interface Negatable
Parameters:
negator -
Returns:

addDerivation

public void addDerivation(Derivation derivation)
Adds a derivation to conclusion.

Parameters:
derivation -

getSlot

protected java.lang.Object getSlot(java.lang.String name)
Returns slot value


toString

public java.lang.String toString()
If pattern is null then outputs class name and list of slots and their values, otherwise formats pattern.

Overrides:
toString in class java.lang.Object

object2Negator

public static boolean object2Negator(java.lang.Object o,
                                     Negator n)
Convenience method to properly negate objects taking implementations of Negatable into account.

Parameters:
o - Object to be negated
n - Negator
Returns:
true if negator negates object

isDerivedFrom

public boolean isDerivedFrom(java.lang.Object fact)
Parameters:
fact -
Returns:
True if the fact equals to one of slots or one of derivations is based on this fact.

toTreeNode

public javax.swing.tree.TreeNode toTreeNode(javax.swing.tree.TreeNode parent,
                                            java.lang.String title)
Specified by:
toTreeNode in interface biz.hammurapi.swing.Visualizable


Copyright © 2005 Hammurapi Group. All Rights Reserved.