jdrew.oo.util
Class Term

java.lang.Object
  extended byjdrew.oo.util.Term
All Implemented Interfaces:
java.lang.Comparable

public class Term
extends java.lang.Object
implements java.lang.Comparable

An object that represents a logic term (Ind, Var, Cterm, Plex, Atom). For a simple term (ind or variable) the subTerms array is set to null, for non-simple terms (atoms, complex terms, plexs) the subTerms array contains the parameters for that term.

Title: OO jDREW

Description: A deductive reasoning engine for Object-Oriented Knowledge in OO RuleML

Copyright: Copyright (c) 2005


Field Summary
 int href
           
 Term oid
           
 int prest
           
 int rest
           
 int role
           
 Term[] subTerms
           
 int symbol
           
 int type
           
 int wsymbol
           
 
Constructor Summary
Term(int symbol, int role, int type)
          Creates a new simple term (variable or ind).
Term(int symbol, int role, int type, int href)
          Create a new simple term with a URI reference or label (must be ind)
Term(int symbol, int role, int type, Term[] subTerms)
          Creates a new complex term (atom, cterm, plex).
Term(int symbol, int role, int type, java.util.Vector subTerms)
          Creates a new complex term (atom, cterm, plex).
 
Method Summary
 int compareTo(java.lang.Object oth)
          Compares one term to another object.
 Term deepCopy()
          Make an identical deep (recursive) copy of this term.
 Term deepCopy(int pside)
          Produces a deep (recursive) copy of this term, with the side member set to the specified value.
 int getPosRest()
          Gets the index of the positional rest parameter.
 int getRest()
          Gets the index of the slotted rest paramater.
 int getRole()
          Gets the role name code for this term.
 java.lang.String getRoleString()
          Gets the role name for this term.
 int getSide()
          Gets the value of the side member variable - this is used by the unification process to keep track of terms.
 Term[] getSubTerms()
          Gets an array of the arguments for this term.
 int getSymbol()
          Gets the symbol code for this term.
 java.lang.String getSymbolForRole(java.lang.String r)
          A method to get the symbol for a role within a complex term.
 java.lang.String getSymbolString()
          Gets the symbol for this term.
 int getType()
          Gets the type code for this term.
 boolean isAtom()
          Test if this term is an atom.
 boolean isCTerm()
          Tests if a term is a complex term.
 void setAtom(boolean atom)
          Sets the boolean atom flag to the passed value, if the atom member variable is set to true and it is not a complex term (subTerms array is set to null) isAtom() will still return false.
 void setRole(int role)
          Sets the role code for this term.
 void setSide(int side)
          Sets the value of the side member variable.
 void setSymbol(int symbol)
          Sets the symbol code for this term.
 void setType(int type)
          Sets the type code for this term.
static java.util.Vector sort(Term[] toSort)
          Sorts an array of jdrew.oo.util.Term values by the role code.
static java.util.Vector sort(java.util.Vector toSort)
          Sorts a Vector of term objects by the role code.
 java.lang.String toPOSLString()
          Returns a string representation of this term in POSL syntax.
 java.lang.String toPOSLString(java.lang.String[] varNames)
          Returns a string representation of this term in POSL syntax.
 java.lang.String toPOSLString(java.lang.String[] varNames, boolean skiprole)
          Returns a string representation of this term in POSL syntax, with the option of omitting the role name.
 Element toRuleML()
          Produces an OO RuleML XML syntax representation of this term, stored in a nu.xom.Element object.
 Element toRuleML(java.lang.String[] varNames)
          Produces an OO RuleML XML syntax representation of this term, stored in a nu.xom.Element object.
 java.lang.String toRuleMLString()
          Produces an OO RuleML XML syntax representation of this term, stored in a string.
 java.lang.String toRuleMLString(java.lang.String[] varNames)
          Produces an OO RuleML XML syntax representation of this term, stored in a string.
 java.lang.String toString()
          Returns a string representation of this term.
 java.lang.String toString(java.lang.String[] varNames)
          Returns a string representation of this term.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

symbol

public int symbol

wsymbol

public int wsymbol

role

public int role

type

public int type

href

public int href

subTerms

public Term[] subTerms

oid

public Term oid

rest

public int rest

prest

public int prest
Constructor Detail

Term

public Term(int symbol,
            int role,
            int type)
Creates a new simple term (variable or ind).

Parameters:
symbol - int The symbol code to be used for this term, for a variable this is a negative number - and the variable name is stored in the variableNames array of the DefiniteClause object, for a ind this is a positive number and the symbol text is stored in the SymbolTable.
role - int The role name code to be used for this term, for a positional argument this is equal to the INOROLE member of the SymbolTable. For slotted arguments the name of the role is stored in the SymbolTable.
type - int The type code to be used for this term, the types for the engine are defined by an RDFS file, and are parsed by the RDFSParser object into the Types system.

Term

public Term(int symbol,
            int role,
            int type,
            int href)
Create a new simple term with a URI reference or label (must be ind)

Parameters:
symbol - int The symbol code to be used for this term, for a variable this is a negative number - and the variable name is stored in the variableNames array of the DefiniteClause object, for a ind this is a positive number and the symbol text is stored in the SymbolTable.
role - int The role name code to be used for this term, for a positional argument this is equal to the INOROLE member of the SymbolTable. For a slotted parameter the role name is stored in the SymbolTable.
type - int The type code to be used for this term, the types for the engine are defined by an RDFS file, and are parsed by the RDFSParser object into the Types system.
href - int The symbol code for the URI for this term; The actual URI is stored in the SymbolTable.

Term

public Term(int symbol,
            int role,
            int type,
            Term[] subTerms)
Creates a new complex term (atom, cterm, plex).

Parameters:
symbol - int value The symbol code to be used for the relation or constructor of this term, this is always a positive number and the symbol text is stored in the SymbolTable.
role - int The role name code to be used for this term, for a positional argument this is equal to the INOROLE member of the SymbolTable. For a slotted parameter the role name is stored in the SymbolTable.
type - int The type code to be used for this term, the types for the engine are defined by an RDFS file, and are parsed by the RDFSParser object into the Types system.
subTerms - Term[] An array containing the terms that will be the parameters of this atom, cterm or plex that is being created.

Term

public Term(int symbol,
            int role,
            int type,
            java.util.Vector subTerms)
Creates a new complex term (atom, cterm, plex).

Parameters:
symbol - int value The symbol code to be used for the relation or constructor of this term, this is always a positive number and the symbol text is stored in the SymbolTable.
role - int value The role name code to be used for this term, for a positional argument this is equal to the INOROLE member of the SymbolTable. For a slotted parameter the role name is stored in the SymbolTable.
type - int value The type code to be used for this term, the types for the engine are defined by an RDFS file, and are parsed by the RDFSParser object into the Types system.
subTerms - Vector value An array containing the terms that will be the parameters of this atom, cterm or plex that is being created.
Method Detail

getSymbolForRole

public java.lang.String getSymbolForRole(java.lang.String r)
A method to get the symbol for a role within a complex term. If the r value is "" this will return the first positional argument. Also if there is more than one value of a role name this will return the first one.

Parameters:
r - String A string containing the name of the role to retrieve the symbol for.
Returns:
String A string containing the symbol associated with the passed role. If this is a variable it will be returned as ?Varx, were x is the variable id, for for complex term this will contain the constructor symbol. Values are not enclosed within " even if this would be required for POSL Syntax.

getSymbol

public int getSymbol()
Gets the symbol code for this term. If it is a complex term this gives the symbol code for the predicate/constructor. If this value is a negative number then this term is a variable.

Returns:
int value - the symbol code for this term.

setSymbol

public void setSymbol(int symbol)
Sets the symbol code for this term.

Parameters:
symbol - int value - the value to set symbol to.

getSymbolString

public java.lang.String getSymbolString()
Gets the symbol for this term. If it is a complex term this gives the symbol for the predicate/constructor. If it is a variable then the symbol is prefixed with a ?.

Returns:
java.lang.String value - the symbol for this term.

getRole

public int getRole()
Gets the role name code for this term. If this is a rest paramater it will be equal to the IREST member of the associated SymbolTable. If this is a positional argument it will be equal to the INOROLE member of the associated SymbolTable.

Returns:
int value - the role code for this term.

setRole

public void setRole(int role)
Sets the role code for this term.

Parameters:
role - int value - the value to set role to.

getRoleString

public java.lang.String getRoleString()
Gets the role name for this term. If this is a positional argument this will be an empty string, for a rest paramater it will be '$REST', otherwise it is the name of the role.

Returns:
java.lang.String value - the role name for this term.

getType

public int getType()
Gets the type code for this term. For an untyped term this will be equal to the IOBJECT member of the TypeHierarchy associated with the clause.

Returns:
int value - the type code for this term.

setType

public void setType(int type)
Sets the type code for this term.

Parameters:
type - int value - the value to set type to.

getSide

public int getSide()
Gets the value of the side member variable - this is used by the unification process to keep track of terms.

Returns:
int value - the current value of the side member.

setSide

public void setSide(int side)
Sets the value of the side member variable.

Parameters:
side - int value - the value to set side to.

getRest

public int getRest()
Gets the index of the slotted rest paramater.

Returns:
int value - the index of the slotted rest parameter within this term, or -1 if this is a simple term or a complex term with no slotted rest paramater.

getPosRest

public int getPosRest()
Gets the index of the positional rest parameter.

Returns:
int value - the index of the position rest parameter within this term, or -1 if this is a simple term or a complex term with no positional rest parameter.

getSubTerms

public Term[] getSubTerms()
Gets an array of the arguments for this term.

Returns:
jdrew.oo.util.Term[] value - a Term[] array of the paramaters for this term. Returns null if this is a simple term (variable or ind).

isCTerm

public boolean isCTerm()
Tests if a term is a complex term.

Returns:
boolean value - true if this term is a complex term (atom, cterm, tup) false otherwise.

isAtom

public boolean isAtom()
Test if this term is an atom.

Returns:
boolean value - true if this term is an atom, false otherwise. This is used only by the output routines, for other things cterms and atoms can be treated the same.

setAtom

public void setAtom(boolean atom)
Sets the boolean atom flag to the passed value, if the atom member variable is set to true and it is not a complex term (subTerms array is set to null) isAtom() will still return false.

Parameters:
atom - boolean value - the value that the atom member should be set to.

toString

public java.lang.String toString()
Returns a string representation of this term. The format of this string is determined by the value of the PRPRINT static variable in the jdrew.oo.Config class. If this is true, this will produce a string in POSL syntax, otherwise it will produce a string in OO RuleML XML syntax. This method is used when you do not have access to the variable names; variables are output as ?Varx - where x is the variable id.

Returns:
java.lang.String value - the String representation of this term.

toString

public java.lang.String toString(java.lang.String[] varNames)
Returns a string representation of this term. The format of this string is determined by the value of the PRPRINT static variable in the jdrew.oo.Config class. If this is true, this will produce a string in POSL syntax, otherwise it will produce a string in OO RuleML XML syntax.

Returns:
java.lang.String value - the String representation of this term.

toPOSLString

public java.lang.String toPOSLString()
Returns a string representation of this term in POSL syntax. This method is used in cases where you do not have access to the variable names associated with the clause - variablenames will be output as ?Varx where x is the variable id.

Returns:
java.lang.String value - the POSL syntax representation of this term.

toPOSLString

public java.lang.String toPOSLString(java.lang.String[] varNames)
Returns a string representation of this term in POSL syntax.

Parameters:
varNames - String[] A string array containing the variable names to use when outputting the string. These are stored in the DefiniteClause that the term is part of.
Returns:
String The POSL syntax representation of the term.

toPOSLString

public java.lang.String toPOSLString(java.lang.String[] varNames,
                                     boolean skiprole)
Returns a string representation of this term in POSL syntax, with the option of omitting the role name. This is used by the mechanism for saving variable bindings.

Parameters:
varNames - String[] A string array containing the variable names to use when outputting the string. These are stored in the DefiniteClause that the term is part of.
skiprole - boolean If true then the role name is omitted from the string output - if false then the role name is included.
Returns:
String The POSL syntax representation of the term.

toRuleMLString

public java.lang.String toRuleMLString()
Produces an OO RuleML XML syntax representation of this term, stored in a string. This version is for the case where you do not have access to the variable names for the term.

Returns:
java.lang.String value - The OO RuleML syntax representation of this, stored as a "pretty printed" string.

toRuleMLString

public java.lang.String toRuleMLString(java.lang.String[] varNames)
Produces an OO RuleML XML syntax representation of this term, stored in a string.

Parameters:
varNames - String[] A string array containing the variable names to use when outputting - these are stored in the DefiniteClause object associated with the term.
Returns:
String A string containing the OO RuleML XML representation of this term.

toRuleML

public Element toRuleML()
Produces an OO RuleML XML syntax representation of this term, stored in a nu.xom.Element object. This version is for when you do not have access to the variable names.

Returns:
Element The OO RuleML syntax representation of this, as a Element value.

toRuleML

public Element toRuleML(java.lang.String[] varNames)
Produces an OO RuleML XML syntax representation of this term, stored in a nu.xom.Element object.

Parameters:
varNames - String[] The variable names associated with the term; these are stored in the DefiniteClause object associated with the term.
Returns:
Element The OO RuleML syntax representation of this, as an Element value.

deepCopy

public Term deepCopy()
Make an identical deep (recursive) copy of this term. This is used when unifying to avoid making changes to the original data strucutres that represent clauses.

Returns:
jdrew.oo.util.Term value - the copy of this term.

deepCopy

public Term deepCopy(int pside)
Produces a deep (recursive) copy of this term, with the side member set to the specified value. This is used when Unifying to avoid making changes to the original data structures that represent clauses.

Parameters:
pside - int The side value that should be stored in the copy.
Returns:
Term The copy of this term.

sort

public static java.util.Vector sort(java.util.Vector toSort)
Sorts a Vector of term objects by the role code.

Parameters:
toSort - Vector A Vector containing only Term objects - to be sorted by the role name code.
Returns:
Vector A Vector containing the sorted terms.

sort

public static java.util.Vector sort(Term[] toSort)
Sorts an array of jdrew.oo.util.Term values by the role code.

Parameters:
toSort - Term[] An array of Term objects to be sorted by the role name code.
Returns:
Vector A Vector containing the sorted terms.

compareTo

public int compareTo(java.lang.Object oth)
Compares one term to another object. If this object is a Term object, it will compare first by the symbol code, then the role name code, the number of paramaters, and finally by the actual paramaters themselves. If the other object is not a Term, then this always returns 1.

Specified by:
compareTo in interface java.lang.Comparable
Parameters:
oth - java.lang.Object value - the other object to compare this term to.
Returns:
int value - the result of the comparison 1 if the other term is "less than", 0 if they are equal, or -1 if the other term is "greater than".