ABLE 2.0.0 07/02/2003 10:25:01

com.ibm.able.data
Class AblePredicate

java.lang.Object
  |
  +--com.ibm.able.data.AblePredicate
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
AbleEmptyListPredicate

public class AblePredicate
extends java.lang.Object
implements java.io.Serializable

This class represents a single predicate-logic predicate with a name, and zero or more arguments which could be Strings, Literals, Variables or other predicates. AblePredicates are processed by the AblePredicateEngine and are used in AblePredicateRules and AblePredicateFacts.

See Also:
Serialized Form

Field Summary
protected  java.util.Vector argList
          The list of arguments which could be Strings, Literals, Variables, or Predicates
protected  int arity
           
static java.lang.String AssertAPredicate
          The name of a special predicate denoting a "asserta" predicate.
static java.lang.String AssertPredicate
          The name of a special predicate denoting a "assert" predicate.
static java.lang.String AssertZPredicate
          The name of a special predicate denoting a "assertz" predicate.
static java.lang.String AtomCharsPredicate
          The name of a special predicate denoting a "atom_charts" predicate.
static java.lang.String AtomConcatPredicate
          The name of a special predicate denoting a "atom_concat" predicate.
static java.lang.String AtomLengthPredicate
          The name of a special predicate denoting a "atom_length" predicate.
static java.lang.String AtomNumberPredicate
          The name of a special predicate denoting a "atom_number" predicate.
static java.lang.String CallPredicate
          The name of a special predicate denoting a "call" predicate.
static java.lang.String ConsultPredicate
          The name of a special predicate denoting a "consult" predicate.
static java.lang.String CutPredicate
          The name of a special predicate denoting a "cut" predicate.
static java.lang.String DontCareSymbol
          The "don't care" symbol for use in predicate clauses.
static AbleEmptyListPredicate EmptyListPredicate
          A special predicate that is the empty "list" predicate: .().
static java.lang.String FailPredicate
          The name of a special predicate denoting a "fail" predicate.
static java.lang.String FunctorPredicate
          The name of a special predicate denoting a "functor" predicate.
static java.lang.String IsListPredicate
          The name of a special predicate denoting a "isList" predicate.
static java.lang.String ListPredicate
          The name of a special predicate denoting a "list" predicate.
static java.lang.String MemberPredicate
          The name of a special predicate denoting a "member" predicate.
protected  AbleLogger myTracer
           
protected  java.lang.String name
           
static java.lang.String NonVarPredicate
          The name of a special predicate denoting a "nonvar" predicate.
static java.lang.String NotPredicate
          The name of a special predicate denoting a "not" predicate.
protected  java.util.Hashtable replacementVars
          This hashtable is used when duplicating a predicate fact or rule during inferencing.
static java.lang.String RetractAllPredicate
          The name of a special predicate denoting a "retractall" predicate.
static java.lang.String RetractPredicate
          The name of a special predicate denoting a "retract" predicate.
static java.lang.String SubAtomPredicate
          The name of a special predicate denoting a "sub_atom" predicate.
static java.lang.String UnifyPredicate
          The name of a special predicate denoting a "unify" predicate.
static java.lang.String UnivPredicate
          The name of a special predicate denoting a "univ" predicate.
protected  java.util.Vector variables
          variables is a list of all of the AbleVariable objects that appear in this predicate (and embedded arguments).
static java.lang.String VarPredicate
          The name of a special predicate denoting a "var" predicate.
 
Constructor Summary
AblePredicate()
           
AblePredicate(AblePredicate thePredicate)
          Construct a copy of the predicate with all local variables duplicated with same name and value.
AblePredicate(java.lang.Object head, AblePredicate tail)
          Construct a standard list predicate with a head and a predicate list as the tail
AblePredicate(java.lang.String name)
          Create an AblePredicate object with specified name
AblePredicate(java.lang.String name, java.util.Vector argList)
          Create an AblePredicate object with name and arguments.
AblePredicate(java.util.Vector argList)
          Create an AblePredicate list object with name "." and arguments.
 
Method Summary
 java.lang.String arlString()
          Return a formal rule language string that describes this clause.
 void clearBindings()
          Sets all variables in this predicate to null values
 void clearBindings(java.util.Vector unboundVars)
          Sets selected variables to null
 AblePredicate createMatchPredicate(java.util.Hashtable replacementVars)
          Create a copy of this predicate with unbound copies of any variables This copy is used in the match() method in AblePredicateEngine
 boolean equals(java.lang.Object otherObj)
           
protected  void findAllVariables()
          Find all contained variables and initialize the variables member
 java.lang.Object getArgument(int index)
          Get an argument from the predicate at specified index
 java.util.Vector getArguments()
          Get the list of arguments in this predicate
 int getArity()
          Get the predicate arity (number of arguments)
 java.util.Vector getBoundVariables()
          Returns all bound variables in this and any contained predicates Note: this list should not contain duplicates
 java.lang.String getFunctor()
          Get the predicate name or functor
 java.lang.Object getHead()
          Get the head (first argument) of a predicate list Note: Caller should use isList() before this method is called
 java.util.Vector getListArguments()
          Return a list predicate as a Vector (i.e.
 java.lang.String getSignature()
          Get a unique signature based on predicate name and arity
protected static AblePredicate getStandardList(java.util.Vector atomList)
          Take this Vector of args and turn it into the standard Prolog/Lisp list structure with a head and tail for each element in the list.
 java.lang.Object getTail()
          Get the tail (second arg) of a predicate list Note: Caller should use isList() before this method is called
 java.lang.String getTemplateString(java.util.Vector theTemplateVars)
          Retrieve a text format string for use by rule templates.
 java.util.Vector getUnboundVariables()
          Get a list of all unbound variables in this predicate (and any contained predicates) Note: this list will not contain any duplicates
 java.util.Vector getVariables()
          Return all variables contained in this predicate
 boolean isBound()
          Returns true if all variables are bound (non-null)
 boolean isCut()
          Test if the predicate name is "cut" with 0-arity (no args)
 boolean isEmptyList()
          Test is this predicate is an empty list
 boolean isFail()
          Test if the predicate name is "fail" with 0 arity (no args)
 boolean isGround()
          Test if this predicate is ground (contains no variables)
 boolean isList()
          Test if this predicate represents a List
 boolean isMember(java.lang.Object fact)
           
 boolean isNot()
          Test if this predicate represents a not(X) predicate
static java.lang.String listToString(AblePredicate predList)
          Take a list predicate and turn it into a [ ] format string
 AblePredicate makeGround()
          Construct a ground instance (contains no variables) of this predicate All bound variables are removed and replaced by literals.
 java.lang.String toString()
          Return a String representation of this predicate
 java.lang.String traceString(int theTraceStringFlavor)
          Retrieve a string describing (the contents of) the object.
 java.lang.String xmlCRdString()
          Return a formal XML "clause read" string that describes this data object.
 java.lang.String xmlString()
          Return a formal XML string that describes this clause.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

name

protected java.lang.String name

arity

protected int arity

argList

protected java.util.Vector argList
The list of arguments which could be Strings, Literals, Variables, or Predicates

replacementVars

protected java.util.Hashtable replacementVars
This hashtable is used when duplicating a predicate fact or rule during inferencing. The original variables are used as the keys, and duplicate variables are constructed and placed in the hashtable values. This is used by createMatchPredicate()

variables

protected java.util.Vector variables
variables is a list of all of the AbleVariable objects that appear in this predicate (and embedded arguments).

myTracer

protected AbleLogger myTracer

DontCareSymbol

public static final java.lang.String DontCareSymbol
The "don't care" symbol for use in predicate clauses.

ListPredicate

public static final java.lang.String ListPredicate
The name of a special predicate denoting a "list" predicate.

IsListPredicate

public static final java.lang.String IsListPredicate
The name of a special predicate denoting a "isList" predicate.

EmptyListPredicate

public static final AbleEmptyListPredicate EmptyListPredicate
A special predicate that is the empty "list" predicate: .().

NotPredicate

public static final java.lang.String NotPredicate
The name of a special predicate denoting a "not" predicate.

CutPredicate

public static final java.lang.String CutPredicate
The name of a special predicate denoting a "cut" predicate.

FailPredicate

public static final java.lang.String FailPredicate
The name of a special predicate denoting a "fail" predicate.

CallPredicate

public static final java.lang.String CallPredicate
The name of a special predicate denoting a "call" predicate.

UnivPredicate

public static final java.lang.String UnivPredicate
The name of a special predicate denoting a "univ" predicate.

AtomCharsPredicate

public static final java.lang.String AtomCharsPredicate
The name of a special predicate denoting a "atom_charts" predicate.

AtomConcatPredicate

public static final java.lang.String AtomConcatPredicate
The name of a special predicate denoting a "atom_concat" predicate.

SubAtomPredicate

public static final java.lang.String SubAtomPredicate
The name of a special predicate denoting a "sub_atom" predicate.

VarPredicate

public static final java.lang.String VarPredicate
The name of a special predicate denoting a "var" predicate.

NonVarPredicate

public static final java.lang.String NonVarPredicate
The name of a special predicate denoting a "nonvar" predicate.

AssertPredicate

public static final java.lang.String AssertPredicate
The name of a special predicate denoting a "assert" predicate.

AssertAPredicate

public static final java.lang.String AssertAPredicate
The name of a special predicate denoting a "asserta" predicate.

AssertZPredicate

public static final java.lang.String AssertZPredicate
The name of a special predicate denoting a "assertz" predicate.

RetractPredicate

public static final java.lang.String RetractPredicate
The name of a special predicate denoting a "retract" predicate.

RetractAllPredicate

public static final java.lang.String RetractAllPredicate
The name of a special predicate denoting a "retractall" predicate.

MemberPredicate

public static final java.lang.String MemberPredicate
The name of a special predicate denoting a "member" predicate.

UnifyPredicate

public static final java.lang.String UnifyPredicate
The name of a special predicate denoting a "unify" predicate.

ConsultPredicate

public static final java.lang.String ConsultPredicate
The name of a special predicate denoting a "consult" predicate.

AtomNumberPredicate

public static final java.lang.String AtomNumberPredicate
The name of a special predicate denoting a "atom_number" predicate.

FunctorPredicate

public static final java.lang.String FunctorPredicate
The name of a special predicate denoting a "functor" predicate.

AtomLengthPredicate

public static final java.lang.String AtomLengthPredicate
The name of a special predicate denoting a "atom_length" predicate.
Constructor Detail

AblePredicate

public AblePredicate()

AblePredicate

public AblePredicate(java.lang.String name)
Create an AblePredicate object with specified name

AblePredicate

public AblePredicate(java.lang.String name,
                     java.util.Vector argList)
Create an AblePredicate object with name and arguments. If this is a predicate list (name = ".") then the argList must end with an empty predicate list (AblePredicate.EmptyListPredicate) or a local variable.
Parameters:
name - A String containing the predicate name
argList - A Vector containing the predicate arguments. These could be other predicates, antecedent or consequent clauses, Symbols (strings) BooleanLiteral, StringLiteral or DoubleLiteral, CharacterLiteral or IntegerLiteral objects. There must be at least two arguments provided. If more than two arguments are provided, the atomic head and tail predicates are included automatically.

AblePredicate

public AblePredicate(java.util.Vector argList)
Create an AblePredicate list object with name "." and arguments. If the argList is empty, an EmptyListPredicate ([]) will be returned. If the argList is non-empty an EmptyListPredicate will be added to the end of the argList and an AblePredicate list will be returned.
Parameters:
argList - A Vector containing the predicate list arguments.

AblePredicate

public AblePredicate(java.lang.Object head,
                     AblePredicate tail)
Construct a standard list predicate with a head and a predicate list as the tail
Parameters:
head - An Object representing the head of the list
tail - A List predicate representing the tail of the list

AblePredicate

public AblePredicate(AblePredicate thePredicate)
Construct a copy of the predicate with all local variables duplicated with same name and value.
Parameters:
thePredicate - The predicate object to be copied
Method Detail

isMember

public boolean isMember(java.lang.Object fact)
                 throws AbleDataException

equals

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

getSignature

public java.lang.String getSignature()
Get a unique signature based on predicate name and arity

getFunctor

public java.lang.String getFunctor()
Get the predicate name or functor

getArity

public int getArity()
Get the predicate arity (number of arguments)

isList

public boolean isList()
Test if this predicate represents a List

isEmptyList

public boolean isEmptyList()
Test is this predicate is an empty list

isNot

public boolean isNot()
Test if this predicate represents a not(X) predicate

getArgument

public java.lang.Object getArgument(int index)
Get an argument from the predicate at specified index
Parameters:
index - The argument (0-based) to retrieve.

getArguments

public java.util.Vector getArguments()
Get the list of arguments in this predicate

getVariables

public java.util.Vector getVariables()
Return all variables contained in this predicate

isGround

public boolean isGround()
Test if this predicate is ground (contains no variables)

isFail

public boolean isFail()
Test if the predicate name is "fail" with 0 arity (no args)

isCut

public boolean isCut()
Test if the predicate name is "cut" with 0-arity (no args)

getHead

public java.lang.Object getHead()
Get the head (first argument) of a predicate list Note: Caller should use isList() before this method is called

getTail

public java.lang.Object getTail()
Get the tail (second arg) of a predicate list Note: Caller should use isList() before this method is called
Returns:
the tail (second arg) of the list

makeGround

public AblePredicate makeGround()
Construct a ground instance (contains no variables) of this predicate All bound variables are removed and replaced by literals.
Returns:
a ground instance of this predicate

isBound

public boolean isBound()
Returns true if all variables are bound (non-null)

getStandardList

protected static AblePredicate getStandardList(java.util.Vector atomList)
Take this Vector of args and turn it into the standard Prolog/Lisp list structure with a head and tail for each element in the list. This method is used by the AblePredicate constructor called by the Parser to convert a Vector of list args into an embedded structure of Predicate lists. so [ 1,2,3,4] looks like .( 1, .( 2, .(3, .(4, []) ) ) ) and [1,2,3 | A] looks like .(1, .(2, .(3, A) ) )
Parameters:
atomList - A vector of list elements (objects)

createMatchPredicate

public AblePredicate createMatchPredicate(java.util.Hashtable replacementVars)
Create a copy of this predicate with unbound copies of any variables This copy is used in the match() method in AblePredicateEngine

getUnboundVariables

public java.util.Vector getUnboundVariables()
                                     throws AbleDataException
Get a list of all unbound variables in this predicate (and any contained predicates) Note: this list will not contain any duplicates

findAllVariables

protected void findAllVariables()
Find all contained variables and initialize the variables member

getBoundVariables

public java.util.Vector getBoundVariables()
Returns all bound variables in this and any contained predicates Note: this list should not contain duplicates

clearBindings

public void clearBindings()
Sets all variables in this predicate to null values

clearBindings

public void clearBindings(java.util.Vector unboundVars)
Sets selected variables to null
Parameters:
unboundVars - A Vector of unbound variables that should be reset to AbleData.StringNull

getListArguments

public java.util.Vector getListArguments()
Return a list predicate as a Vector (i.e. unwind the list) Note: isList() should be called on this predicate before calling this method

listToString

public static java.lang.String listToString(AblePredicate predList)
Take a list predicate and turn it into a [ ] format string
Parameters:
predList - A predicate list object

arlString

public java.lang.String arlString()
Return a formal rule language string that describes this clause.
Returns:
A String that describes this clause in formal rule language.

getTemplateString

public java.lang.String getTemplateString(java.util.Vector theTemplateVars)
Retrieve a text format string for use by rule templates. The string contains "{n}" strings, where the index 'n' corresponds to the template variables defined in the rule template. This string is based on the standard arlString() representation of the rule. After replacement of the template variable values, the resulting string must be a valid ARL format string that can be parsed.
Parameters:
theTemplateVars - An ordered list of template variables referenced by this rule.
Returns:
A Text format string used to create a new rule instance.

xmlCRdString

public java.lang.String xmlCRdString()
Return a formal XML "clause read" string that describes this data object.
Returns:
A String describing the data object in XML.

xmlString

public java.lang.String xmlString()
Return a formal XML string that describes this clause.
Returns:
A String that describes this clause in XML.

toString

public java.lang.String toString()
Return a String representation of this predicate
Overrides:
toString in class java.lang.Object

traceString

public java.lang.String traceString(int theTraceStringFlavor)
Retrieve a string describing (the contents of) the object.
Parameters:
theFlavor - An Able.TraceStringFlavor value.

Returns:
A String containing the current contents of the object.

ABLE 2.0.0 07/02/2003 10:25:01

(C) Copyright IBM Corporation 1999, 2003