org.aspic.inference
Class Rule

java.lang.Object
  extended by org.aspic.inference.Element
      extended by org.aspic.inference.Constant
          extended by org.aspic.inference.Term
              extended by org.aspic.inference.Rule
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable

public class Rule
extends Term

A Rule is a specialised Term, rule/4. The four parameters are:

Rule is also the only class that is explicitly allowed into the Knowledge Base.

The first two parameters arise naturally from a prolog (i.e. horn clause based) rule system. The last two parameters fix us into the argumentation space and need some explanation.

dob allows us to place an ordering over arguments that are developed from facts and rules,List when we develop those arguments using a particular evaluation strategy (i.e. weakest_link or last_link).

name allows a particular rule to be undercut by other rules and facts. It is itself a Term and can be thought of as a "hidden premise". because when developing an argument based on a rule, the algorithm checks that it can develop arguments for each of the rule's premises (members of the antecedent) *and* it's name.

A knowledge base is a collection of Rules

A KnowledgeBase contains a list of rules. Facts and beliefs are represented in a KnowledgeBase as Rules with an empty antecedent. In order to distinguish between proper rules (i.e. those that have non-empty antecendents) and facts/beliefs a helper method, isFact() is provided.

Link between rule.name and knowledge base.

Because of the "hidden premise" nature of a rule's name, a knowledge base automatically adds a rule's name as a fact/belief when you add a rule to the knowledge base. This automatically generated fact/belief is known as the rule hook. If the rule is proper and unnamed then the knowledge base automatically assigns the rule a name and adds that name to the knowledgebase. Care is taken that automatically assigned names do not conflict with user assigned names. To help with this process, isAutoNamed and isAutoGenerated properties are provided.

Caption and Description

Caption and Description fields allow human users to mark-up a rule with a human-readable identifier (caption) and description.

Author:
mjs (matthew.south @ cancer.org.uk)
See Also:
Serialized Form

Constructor Summary
Rule()
          Default constructor.
Rule(Constant fact)
          Constructor for a fact
Rule(Constant belief, java.lang.Double dob)
          Constructor for a belief (a defeasible assertion, with belief less than 1.0)
Rule(Constant consequent, ElementList antecedent)
          Constructor for a strict rule
Rule(Constant consequent, ElementList antecedent, java.lang.Double dob)
          Constructor for a defeasible rule
Rule(Constant consequent, ElementList antecedent, java.lang.Double dob, Constant name)
          General purpose constructor
 
Method Summary
 Rule apply(Substitution subs)
          Return copy of this Element with the substitution applied.
 java.lang.Object clone()
          An element is incompletely cloned.
 boolean equals(java.lang.Object obj)
           
 ElementList getAntecedent()
          Getter for Rule's antecendent.
 java.lang.String getCaption()
          Getter for caption.
 java.lang.String getClaimCaption()
           
 java.lang.String getClaimDescription()
           
 Constant getConsequent()
          Getter for Rule consequent.
 java.lang.String getDescription()
          Getter for description.
 java.lang.Double getDob()
          Getter for Rule's Degree of Belief.
 Constant getName()
          Getter for Rule name.
 int hashCode()
           
 java.lang.String inspect()
          (idea from the Ruby prototype) inspect allows us to see a representation of the text expression that the object is based on.
 java.lang.String inspect(boolean showAutoGeneratedRuleNames, boolean showRuleHooks)
          A version of inspect that allows you to optionally hide all of the auto generated artifacts.
 boolean isFact()
          Interrogation method to see if this rule actually is a rule, or a rule without a body, which is a fact.
 boolean isStrict()
          Check whether Rule is defeasible or strict.
 void setAntecedent(ElementList antecedent)
          Setter for Rule's antecedent.
 void setCaption(java.lang.String caption)
          Setter for caption.
 void setClaimCaption(java.lang.String claimCaption)
           
 void setClaimDescription(java.lang.String claimDescription)
           
 void setConsequent(Constant consequent)
          Setter for the Rule's consequent.
 void setDescription(java.lang.String description)
          Setter for description.
 void setDob(java.lang.Double dob)
          Setter for Rule's Degree of Belief.
 void setName(Constant name)
          Setter for Rule name.
 void write(KnowledgeWriter writer)
          Using the Visitor pattern, this method allows the details of an Element to be written in different ways.
 
Methods inherited from class org.aspic.inference.Term
addArg, getArg, isEqualModuloVariables, isGrounded, isUnifiable, negation, numberOfArgs, ruleTag, setArg, setArgList, setKnowledgeBase, unify
 
Methods inherited from class org.aspic.inference.Constant
getFunctor, setFunctor
 
Methods inherited from class org.aspic.inference.Element
getId, getKnowledgeBase, setId, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Rule

public Rule()
Default constructor.


Rule

public Rule(Constant fact)
Constructor for a fact

Parameters:
fact - strict constant/term

Rule

public Rule(Constant belief,
            java.lang.Double dob)
Constructor for a belief (a defeasible assertion, with belief less than 1.0)

Parameters:
belief - defeasible constant/term
dob - degree of belief (0, 1.0]

Rule

public Rule(Constant consequent,
            ElementList antecedent)
Constructor for a strict rule

Parameters:
consequent - claim
antecedent - premises

Rule

public Rule(Constant consequent,
            ElementList antecedent,
            java.lang.Double dob)
Constructor for a defeasible rule

Parameters:
consequent - claim
antecedent - premises
dob - degree of belief (0, 1.0]

Rule

public Rule(Constant consequent,
            ElementList antecedent,
            java.lang.Double dob,
            Constant name)
General purpose constructor

Parameters:
consequent - claim
antecedent - premises
dob - degree of belief (0, 1.0]
name - consumer supplied rule name
Method Detail

equals

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

hashCode

public int hashCode()
Overrides:
hashCode in class Term

getConsequent

public Constant getConsequent()
Getter for Rule consequent.

Returns:
The Rule's consequent (or head).

setConsequent

public void setConsequent(Constant consequent)
Setter for the Rule's consequent.

Parameters:
consequent - A Constants or Terms.

getAntecedent

public ElementList getAntecedent()
Getter for Rule's antecendent.

Returns:
The Rule's antecedent (or tail).

setAntecedent

public void setAntecedent(ElementList antecedent)
Setter for Rule's antecedent.

Parameters:
antecedent - An ElementList of Constants or Terms.

getDob

public java.lang.Double getDob()
Getter for Rule's Degree of Belief.

Returns:
degree of belief for Rule (0, 1.0]

setDob

public void setDob(java.lang.Double dob)
Setter for Rule's Degree of Belief.

Parameters:
dob - Degree of Belief (0, 1.0]

getName

public Constant getName()
Getter for Rule name.

Returns:
the Rule's name, or null if it's not yet been set.

setName

public void setName(Constant name)
Setter for Rule name.

Parameters:
name - the rule's name to set.

inspect

public java.lang.String inspect()
Description copied from class: Element
(idea from the Ruby prototype) inspect allows us to see a representation of the text expression that the object is based on. Not implemented by overriding toString() because it's still useful to be able to inspect the objectID which toString returns.

Overrides:
inspect in class Term
Returns:
String representation of this knowledge atom

inspect

public java.lang.String inspect(boolean showAutoGeneratedRuleNames,
                                boolean showRuleHooks)
A version of inspect that allows you to optionally hide all of the auto generated artifacts.

Parameters:
showAutoGeneratedRuleNames - Allows you to hide automatically generated rule names
showRuleHooks - Allows you to hide the automatically generated "rule hook" rules
Returns:
String representing a Prolog representation of the rule.

apply

public Rule apply(Substitution subs)
Description copied from class: Element
Return copy of this Element with the substitution applied.

Overrides:
apply in class Term
Parameters:
subs - Substitution to apply
Returns:
Copy of this Element with substitution applied to it.

isFact

public boolean isFact()
Interrogation method to see if this rule actually is a rule, or a rule without a body, which is a fact.

Returns:
true if this rule is actually a fact

isStrict

public boolean isStrict()
Check whether Rule is defeasible or strict.

Returns:
true if this object is a rule and it's dob is 1.0

write

public void write(KnowledgeWriter writer)
Description copied from class: Element
Using the Visitor pattern, this method allows the details of an Element to be written in different ways.

Overrides:
write in class Term
Parameters:
writer - the object that does the writing.

clone

public java.lang.Object clone()
Description copied from class: Element
An element is incompletely cloned. Everything except it's knowledgeBase reference is cloned.

Overrides:
clone in class Term

getCaption

public java.lang.String getCaption()
Getter for caption.

Returns:
human readable identifier for rule.

setCaption

public void setCaption(java.lang.String caption)
Setter for caption.

Parameters:
caption - human readable identifier for rule.

getDescription

public java.lang.String getDescription()
Getter for description.

Returns:
Human readable description of rule.

setDescription

public void setDescription(java.lang.String description)
Setter for description.

Parameters:
description - Human readable description of rule.

getClaimCaption

public java.lang.String getClaimCaption()

setClaimCaption

public void setClaimCaption(java.lang.String claimCaption)

getClaimDescription

public java.lang.String getClaimDescription()

setClaimDescription

public void setClaimDescription(java.lang.String claimDescription)