com.agentfactory.cldc.logic
Class FOS

java.lang.Object
  extended by com.agentfactory.cldc.logic.FOS

public class FOS
extends java.lang.Object

The first order structure class represents one of the primary logical componsents of Agent Factory/AFME. It provides an abstract or symbolic representation of the information content.

Author:
Conor Muldoon

Field Summary
static char CLOSE_BRACKET
           
static char OPEN_BRACKET
           
 
Method Summary
 void addToTable(java.util.Hashtable table, java.lang.Object object)
          Adds the specified object to the hash table using the functor of the first order structure as the key.
 void append(java.lang.StringBuffer buffer)
          Appends the first order structure to the specified string buffer.
 FOS apply(SubstitutionSet sub)
          Applies the specified substitution set to the first order structure.
 void buildSet(FOS fos, SubstitutionSet solution)
          Applies the substitution set to the arguments of this first order structure and to the arguments of the specified first order structure.
 boolean containsChar(char c)
          Checks whether the first order structure contains the specified character.
static FOS createFOS(java.lang.String string)
          Creates a first order structure from the specified string represention if the string does not represent a variable.
 boolean equals(FOS fos)
          Checks whether this first order structure is equal to the specified first order structure.
 boolean functorEquals(java.lang.Object object)
          Tests whether the functor equals the specified object.
 boolean functorStartsWith(java.lang.String string)
          Checks whether the functor of this first order structure starts with the specified string.
 java.lang.Object getFromTable(java.util.Hashtable table)
          Obtains the object from the hash table whose key is the functor of the first order structure.
 int hashCode()
          Returns the hash code for the first order structure.
 boolean hasNext()
          Tests if the first order structure has more arguments.
 FOS invert()
          Returns an inverted first order structure.
 boolean isNot()
          Tests whether this is an inverted first order structure.
 boolean isTrue()
          Test whether this is a true first order structure.
 boolean matches(FOS f)
          Tests whether this first order structure matches the specified first order structure.
 FOS next()
          Returns the next argument in the first order structure and increments the internal counter, which is used to determine the current argument.
 java.lang.Object removeFromTable(java.util.Hashtable table)
          Removes the object from the hash table whose key is the functor of this first order structure.
 void reset()
          Resets the first order structure to the state in which the next method has never been called.
 java.lang.String toString()
          converts this first order structure to a string.
 
Methods inherited from class java.lang.Object
equals, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

OPEN_BRACKET

public static final char OPEN_BRACKET
See Also:
Constant Field Values

CLOSE_BRACKET

public static final char CLOSE_BRACKET
See Also:
Constant Field Values
Method Detail

createFOS

public static FOS createFOS(java.lang.String string)
                     throws MalformedLogicException
Creates a first order structure from the specified string represention if the string does not represent a variable. If the string does represent a variable and the varible was previously created, returns the previously created first order structure. If the variable was not preiviously created, returns a new first order structure for the variable.

Parameters:
string - the specified string representation.
Returns:
either a variable or composite first order structure.
Throws:
MalformedLogicException - if there is a logic error.

invert

public FOS invert()
Returns an inverted first order structure. An inverted first order structure is one in which the truth value has been toggle. In AFME, a first order structure that is preceded with the ! symbol is negated. ! represent not. So for instance, !a represent not a. If !a was passed to this method, a would be returned. If a was passed to this method, !a would be returned.

Returns:
an inverted first order structure.

isNot

public boolean isNot()
Tests whether this is an inverted first order structure.

Returns:
true if this is an inverted first order structure, false otherwise.

hasNext

public boolean hasNext()
Tests if the first order structure has more arguments.

Returns:
true if the first order structure has more arguments, false otherwise.

next

public FOS next()
Returns the next argument in the first order structure and increments the internal counter, which is used to determine the current argument. Once all of the arguments have been returen, a null argument is returned the first time the next() method is subsequently called. A sentinel is used so as that an if statement is not required to check for the last element and to thereby improve efficiency.

Returns:
the next argument in the first order structure.

reset

public void reset()
Resets the first order structure to the state in which the next method has never been called. The reset method is recursively called on each of the first order structure's children.


containsChar

public boolean containsChar(char c)
Checks whether the first order structure contains the specified character.

Parameters:
c - the character to check for.
Returns:
true if the first order structure contains the specified character, false otherwise.

functorEquals

public boolean functorEquals(java.lang.Object object)
Tests whether the functor equals the specified object.

Parameters:
object - the object to compare the functor to.
Returns:
true if the functor is equal to the specified object, false otherwise.

removeFromTable

public java.lang.Object removeFromTable(java.util.Hashtable table)
Removes the object from the hash table whose key is the functor of this first order structure.

Parameters:
table - the hash table to remove the object from.
Returns:
the object from the hash table whose key is equal to the functor of this first order structure, null if no such object in the table.

addToTable

public void addToTable(java.util.Hashtable table,
                       java.lang.Object object)
Adds the specified object to the hash table using the functor of the first order structure as the key.

Parameters:
table - the table the object is to be added to.
object - the object to add to the table.

getFromTable

public java.lang.Object getFromTable(java.util.Hashtable table)
Obtains the object from the hash table whose key is the functor of the first order structure.

Parameters:
table - the hash table to obtain the object from.
Returns:
an object from the hashtable whose key is the functor of the first order structure, null if there is no such object.

isTrue

public boolean isTrue()
Test whether this is a true first order structure. A first order structure is true in AFME if it has no arguments and its functor is equal to the string true. A true first order structure has a special meaning in AFME. If true is encoded in a belief sentence or commitment, the agent need not adopt a belief true for the commitment to hold or the belief sentence to be evaluated to true. It is taken that under all circumstance the evaluation will be true.

Returns:
true if this first order structure is true, false otherwise.

matches

public boolean matches(FOS f)
Tests whether this first order structure matches the specified first order structure. A matching is defined recursively as the following: Two first order structures match if (1) either are variables or (2) they have the same functor, same number (n) of arguments, and each argument a(i) of the specified first order structure matches each argument b(i) of this first order structure where i = 0 to n-1 and arguments are 0 indexed. So for example, hello(Alice) and hello(Bob) would both match with hello(?x) but they would not match with each other. It should be noted that hello(Alice(inChains)) would also match with hello(?x). This is because ?x would match with Alice(inChains) since ?x is a variable.

Parameters:
f - the specified first order structure.
Returns:
true if the first order structures match, false otherwise.

buildSet

public void buildSet(FOS fos,
                     SubstitutionSet solution)
Applies the substitution set to the arguments of this first order structure and to the arguments of the specified first order structure. For each ordinal pair of arguments, if one of the arguments are variables, a substitution is added to the set linking the two arguments. If neither arguments are variables, the buildSet method is called recursively.

Parameters:
fos - the first order structure used to build the set mappings.
solution - the substitution set being built.

apply

public FOS apply(SubstitutionSet sub)
Applies the specified substitution set to the first order structure.

Parameters:
sub - the specified substitution set.
Returns:
a first order structure that has had the substituion set applied to it.

append

public void append(java.lang.StringBuffer buffer)
Appends the first order structure to the specified string buffer.

Parameters:
buffer - the string buffer that the first order structure is appended to.

hashCode

public int hashCode()
Returns the hash code for the first order structure.

Overrides:
hashCode in class java.lang.Object

toString

public java.lang.String toString()
converts this first order structure to a string.

Overrides:
toString in class java.lang.Object

functorStartsWith

public boolean functorStartsWith(java.lang.String string)
Checks whether the functor of this first order structure starts with the specified string.

Parameters:
string - the specified string.
Returns:
true if the specified string is a prefix of the functor, false otherwise.

equals

public boolean equals(FOS fos)
Checks whether this first order structure is equal to the specified first order structure.

Parameters:
fos - the specified first order structure.
Returns:
true if this first order structure is equal to the specified first order structure, false otherwise.