ai.krr.fol
Class Term

java.lang.Object
  extended by ai.krr.fol.Term
All Implemented Interfaces:
java.lang.Cloneable, java.lang.Comparable<Term>
Direct Known Subclasses:
Constant, FunctionTerm, Variable

public abstract class Term
extends java.lang.Object
implements java.lang.Comparable<Term>, java.lang.Cloneable

A Term represents an object in a conceptualisation of some domain. Terms are mostly used in logical expressions. Currently, there are three kinds of Term implemented: Constant, Variable, and FunctionTerm.

Author:
Gerhard Wickler

Constructor Summary
Term()
           
 
Method Summary
protected abstract  void addConstants(java.util.Set<Symbol> sys)
           This function adds all the constant Symbols used in this Term to the given Set.
protected abstract  void addFreeVariables(java.util.Set<Variable> free, java.util.Set<Variable> bound)
           This function adds the free Variables in this Term to the first given Set.
protected abstract  void addFunctions(java.util.Map<Symbol,java.lang.Integer> sys)
           This function adds all the function Symbols used in this Term to the given Set.
protected abstract  void addVariables(java.util.Set<Variable> vars)
           This function adds all the Variables in this Term to the given Set.
abstract  Term clone()
           Returns a copy of this Term.
abstract  Term clone(Substitution s)
           Returns a copy of this Term with Variables replaced according to the given Substitution.
abstract  int compareTo(Term term)
           This function compares this Term to the given Term.
abstract  java.lang.Object evaluate(Interpretation i, Substitution s)
           This function evaluates this Term under the given Interpretation and Substitution for Variables.
abstract  boolean exceedsDepth(int depth)
           This function tests whether this Term exceeds the given depth which should be a non-negative integer.
abstract  int getDepth()
           This function returns the nesting depth of this Term.
 java.util.Set<Variable> getVariables()
           This function adds all the Variables in this Term to the returned Set.
abstract  boolean isGround()
           This function tests whether this Term contains any Variables.
abstract  boolean unify(Term other, Substitution s)
           This function attempts to extend the given Substitution so that this Term and the given Term are unified.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Term

public Term()
Method Detail

clone

public abstract Term clone()

Returns a copy of this Term. Variables and Symbols in the copy will be the same as the original ones.

Overrides:
clone in class java.lang.Object
Returns:
an equal copy of this Term

clone

public abstract Term clone(Substitution s)

Returns a copy of this Term with Variables replaced according to the given Substitution. Symbols in the copy will be the same as the original ones but Variables will be replaced by the respective Terms in the given Substitution. A Variable not occurring in the Substitution will be replaced by a new (different) Variable with the same name. The given Substitution will be extended to include the mappings of old Variables to new ones (if the Substitution allows for this).

This function can be used to generate a copy of this Term that contains a new set of Variables. The given Substitution should be a new, empty Substitution in this case. Otherwise cloning can be seen as instantiating the Term.

Parameters:
s - the Substitution that determines how to replace Variables
Returns:
a new Term that is an instance of this Term; the Substitution s will be extended with any new Variable replacements introduced

isGround

public abstract boolean isGround()

This function tests whether this Term contains any Variables.

Returns:
true iff this Term contains no Variables

getDepth

public abstract int getDepth()

This function returns the nesting depth of this Term. The depth of a Constant or Variable is defined to be 0. The depth of a FunctionTerm is the maximum depth of the sub-Term plus 1.

Returns:
the depth of this Term when seen as a tree

exceedsDepth

public abstract boolean exceedsDepth(int depth)

This function tests whether this Term exceeds the given depth which should be a non-negative integer.

Parameters:
depth - the depth value that is tested for
Returns:
true iff this.getDepth() > depth

evaluate

public abstract java.lang.Object evaluate(Interpretation i,
                                          Substitution s)

This function evaluates this Term under the given Interpretation and Substitution for Variables. If all sub-Terms occurring in the Term have a value assigned by the Interpretation the result will be an Object which is an element of the Interpretation's domain.

Parameters:
i - the Interpretation giving values for Terms
s - the Substitution for Variables occurring in this Term
Returns:
the value of this Term under the given Interpretation

unify

public abstract boolean unify(Term other,
                              Substitution s)

This function attempts to extend the given Substitution so that this Term and the given Term are unified. It returns true if and only if this is possible. For example, if t1 and t2 are Terms then:

 Substitution subst = new Substitution();
 boolean unif = t1.unify(t2, subst);
 Term uniTerm = t1.clone(subst);
 

will firstly create a new, empty Substitution subst. This will be modified in the call to unify. If unification was possible unif will contain the value true and subst will be the unifying Substitution. Otherwise it will have an undefined value. In the latter case the last line should not be executed. If unification was successful though it is safe and will set uniTerm to the expected value.

Parameters:
other - the other Term this one is to be unified with
s - the Substitution to be extended for the unification
Returns:
whether a unifying extension of the given Substitution was possible

compareTo

public abstract int compareTo(Term term)

This function compares this Term to the given Term. The order between different kinds of Term is arbitrarily defined as (ascending): Constant, Variable, FunctionTerm.

Specified by:
compareTo in interface java.lang.Comparable<Term>
Parameters:
term - the Term to which this Term is to be compared
Returns:
0 if the two Terms are identical; -1 if the given Term should come after this Term; and +1 if the given Term should come before this Term

getVariables

public java.util.Set<Variable> getVariables()

This function adds all the Variables in this Term to the returned Set.

Returns:
a Set containing all Variables occurring in this Term

addConstants

protected abstract void addConstants(java.util.Set<Symbol> sys)

This function adds all the constant Symbols used in this Term to the given Set.

Parameters:
sys - the Set that will contain all the Constants

addFunctions

protected abstract void addFunctions(java.util.Map<Symbol,java.lang.Integer> sys)

This function adds all the function Symbols used in this Term to the given Set.

Parameters:
sys - the Set that will contain all the function names

addVariables

protected abstract void addVariables(java.util.Set<Variable> vars)

This function adds all the Variables in this Term to the given Set.

Parameters:
vars - a Set of Variables that will be extended

addFreeVariables

protected abstract void addFreeVariables(java.util.Set<Variable> free,
                                         java.util.Set<Variable> bound)

This function adds the free Variables in this Term to the first given Set. Variables in the second given Set are bound and will not be added.

Parameters:
free - a Set of free Variables that will be extended
bound - a Set of bound Variables that will not be added