ABLE 2.3.0 07/13/2005 14:21:00

com.ibm.able.data
Class AblePredicate

java.lang.Object
  extended bycom.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.
 java.lang.String armlString()
          Return a formal XML 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; that is, unwind the list.
 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
 int hashCode()
           
 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, 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.

See Also:
Constant Field Values

ListPredicate

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

See Also:
Constant Field Values

IsListPredicate

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

See Also:
Constant Field Values

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.

See Also:
Constant Field Values

CutPredicate

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

See Also:
Constant Field Values

FailPredicate

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

See Also:
Constant Field Values

CallPredicate

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

See Also:
Constant Field Values

UnivPredicate

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

See Also:
Constant Field Values

AtomCharsPredicate

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

See Also:
Constant Field Values

AtomConcatPredicate

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

See Also:
Constant Field Values

SubAtomPredicate

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

See Also:
Constant Field Values

VarPredicate

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

See Also:
Constant Field Values

NonVarPredicate

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

See Also:
Constant Field Values

AssertPredicate

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

See Also:
Constant Field Values

AssertAPredicate

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

See Also:
Constant Field Values

AssertZPredicate

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

See Also:
Constant Field Values

RetractPredicate

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

See Also:
Constant Field Values

RetractAllPredicate

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

See Also:
Constant Field Values

MemberPredicate

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

See Also:
Constant Field Values

UnifyPredicate

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

See Also:
Constant Field Values

ConsultPredicate

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

See Also:
Constant Field Values

AtomNumberPredicate

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

See Also:
Constant Field Values

FunctorPredicate

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

See Also:
Constant Field Values

AtomLengthPredicate

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

See Also:
Constant Field Values
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
Throws:
AbleDataException

equals

public boolean equals(java.lang.Object otherObj)

hashCode

public int hashCode()

getSignature

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

Returns:
the signature string

getFunctor

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

Returns:
the signature string

getArity

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

Returns:
the arity

isList

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

Returns:
true if the predicate name is "." which means it is a list

isEmptyList

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

Returns:
true if the predicate name is "." which means it is a list and it has zero arguments which means it is empty

isNot

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

Returns:
true if the predicate name is "not"

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.
Returns:
the argument Object.

getArguments

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

Returns:
the Vector of argument objects.

getVariables

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

Returns:
the Vector of variables.

isGround

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

Returns:
true if this predicate is ground, false otherwise

isFail

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

Returns:
true if the predicate is the "fail" predicate

isCut

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

Returns:
true if the predicate is the "cut" predicate

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

Returns:
the head (first arg) of the list

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

Parameters:
replacementVars - A set of unbound variable instances to be used as replacements when a copy of this predicate is constructed.

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

Returns:
a Vector of unbound variables
Throws:
AbleDataException

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; that is, unwind the list. Note: isList() should be called on this predicate before calling this method

Returns:
A Vector containing the list elements

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
Returns:
A formatted string representation of the list with brackets [ ]

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.

armlString

public java.lang.String armlString()
Return a formal XML string that describes this clause.

Returns:
A String that describes this clause in XML.

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


traceString

public java.lang.String traceString(int theTraceStringFlavor)
Retrieve a string describing (the contents of) the object.

Parameters:
theTraceStringFlavor - An Able.TraceStringFlavor value.

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

ABLE 2.3.0 07/13/2005 14:21:00

(C) Copyright IBM Corporation 1999, 2005