ai.krr.fol
Class Atom

java.lang.Object
  extended by ai.krr.fol.Sentence
      extended by ai.krr.fol.Atom
All Implemented Interfaces:
inf.compilers.SyntaxAdaptable, java.lang.Cloneable, java.lang.Comparable<Sentence>

public class Atom
extends Sentence

An Atom is one of the most basic building blocks for a Sentence. It simply consists of a predicate over some arguments that can be either true or false.

Author:
Gerhard Wickler

Nested Class Summary
 
Nested classes/interfaces inherited from class ai.krr.fol.Sentence
Sentence.SubSentenceIterator
 
Constructor Summary
Atom(NamedSymbol pSymbol, java.util.List<Term> someTerms)
           This constructor for an Atom takes a predicate Symbol and a List of argument Terms.
Atom(NamedSymbol pSymbol, Term... someTerms)
           This constructor for an Atom takes a predicate Symbol and a number of argument Terms.
 
Method Summary
protected  void addBoundVariables(java.util.Set<Variable> bound)
           This function adds the bound Variables in this Sentence to the given Set.
protected  void addConstants(java.util.Set<Symbol> sys)
           This function adds all the constant Symbols used in this Sentence to the given Set.
protected  void addFreeVariables(java.util.Set<Variable> free, java.util.Set<Variable> bound)
           This function adds the free Variables in this Sentence to the first given Set.
protected  void addFunctions(java.util.Map<Symbol,java.lang.Integer> sys)
           This function adds all the function Symbols used in this Sentence to the given Set.
protected  void addPredicates(java.util.Map<NamedSymbol,java.lang.Integer> sys)
           This function adds all the predicate Symbols used in this Sentence to the given Set.
 Atom clone()
           Returns a shallow copy of this Atom.
 Atom clone(Substitution s)
           Returns a deep copy of this Atom with Variables replaced according to the given Substitution.
 int compareTo(Atom other)
           This function compares this Atom to the given Atom.
 int compareTo(Sentence other)
           This function compares this Atom to the given Sentence.
 boolean equals(Atom other)
           A Atom is equal to any other Atom that consists of an equal predicate symbol followed by an equal number of equal Terms.
 boolean equals(java.lang.Object obj)
           A Atom is only equal to another Atom.
 BooleanSymbol evaluate(Interpretation ipt, Substitution s)
           This function evaluates this Sentence under the given Interpretation and Substitution for Variables.
 boolean exceedsDepth(int depth)
           This function tests whether this Sentence exceeds the given depth which should be a non-negative integer.
 Term[] getArguments()
           This function returns the argument Terms of this Atom.
 int getClassOrderIndex()
           This function returns the index used for ordering Sentences across different classes.
 int getDepth()
           This function returns the nesting depth of this Sentence.
 NamedSymbol getPredicate()
           This function returns the predicate symbol used in this Atom which is a NamedSymbol.
 int hashCode()
           This function returns the hash code of this Atom.
 boolean isFunctionFree()
           This function tests whether this Atom contains any FunctionTerms.
 boolean isGround()
           This function tests whether this Atom contains any Variables.
protected  Sentence skolemize(boolean isNegated, Term[] uqVars, Substitution s)
           This function computes a skolemized version of this Sentence.
protected  Sentence toCNF(boolean isNegated)
          This function returns a new Literal which contains the proposition contained in this Atom.
protected  Sentence toDNF(boolean isNegated)
          This function returns a new Literal which contains the proposition contained in this Atom.
 java.lang.String toString()
           A Atom is printed as <predicate> ( <Term>+ ).
 boolean unify(Atom other, Substitution s)
           This function attempts to extend the given Substitution so that this Atom and the given Atom are unified.
 
Methods inherited from class ai.krr.fol.Sentence
allSubSentences, getBoundVariables, getConstants, getFreeVariables, getFunctions, getPredicates, prettyPrint, read, skolemize, toClauseForm, toCNF, toDNF, write
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Atom

public Atom(NamedSymbol pSymbol,
            java.util.List<Term> someTerms)

This constructor for an Atom takes a predicate Symbol and a List of argument Terms.

Parameters:
pSymbol - the predicate symbol
someTerms - the List of argument Terms

Atom

public Atom(NamedSymbol pSymbol,
            Term... someTerms)

This constructor for an Atom takes a predicate Symbol and a number of argument Terms.

Parameters:
pSymbol - the function symbol
someTerms - the argument Terms
Method Detail

clone

public Atom clone()

Returns a shallow copy of this Atom. Argument Terms in the copy will be the same as the original ones.

Specified by:
clone in class Sentence
Returns:
an equal copy of this Atom

clone

public Atom clone(Substitution s)

Returns a deep copy of this Atom 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. The function uses Term.clone(Substitution) to generate the copies of all the argument Terms in this Atom.

Specified by:
clone in class Sentence
Parameters:
s - the Substitution that tells us how to replace Variables
Returns:
a new Atom that is an instance of this Atom; the Substitution s will extended with any new Variable replacements introduced

getDepth

public int getDepth()

This function returns the nesting depth of this Sentence. The depth of an Atom is the depth of the deepest Term it contains plus one.

Specified by:
getDepth in class Sentence
Returns:
the depth of this Sentence when seen as a tree

exceedsDepth

public boolean exceedsDepth(int depth)

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

Specified by:
exceedsDepth in class Sentence
Parameters:
depth - the depth value that is tested for
Returns:
true iff this.getDepth() > depth

getClassOrderIndex

public final int getClassOrderIndex()

This function returns the index used for ordering Sentences across different classes. This index of this class is defined to be 1.

Specified by:
getClassOrderIndex in class Sentence
Returns:
an integer indicating how this type of Sentence is to be ordered with respect to different types of Sentence

compareTo

public int compareTo(Sentence other)

This function compares this Atom to the given Sentence. The order between different kinds of Sentence is arbitrarily defined as (ascending): TruthValue, Atom, Literal, NegatedSentence, ConnectedSentence, BinaryConnectedSentence, QuantifiedSentence.

Specified by:
compareTo in interface java.lang.Comparable<Sentence>
Specified by:
compareTo in class Sentence
Parameters:
other - the Sentence to which this Atom is to be compared
Returns:
0 if the two Atoms are equal; -1 if the given Sentence should come after this Atom; and +1 if the given Sentence should come before this Atom

evaluate

public BooleanSymbol evaluate(Interpretation ipt,
                              Substitution s)

This function evaluates this Sentence under the given Interpretation and Substitution for Variables. Note that the given Substitution must ground all the free Variables occurring in this Sentence. If this Sentence is already ground the given Substitution may be null. If all Atoms and Terms occurring in the Sentence have a value assigned by the Interpretation the result will be a BooleanSymbol. Otherwise it will be null.

Specified by:
evaluate in class Sentence
Parameters:
ipt - the Interpretation giving values for Atoms and Terms
s - the Substitution for Variables occurring in this Term
Returns:
the value of this Term under the given Interpretation

getPredicate

public final NamedSymbol getPredicate()

This function returns the predicate symbol used in this Atom which is a NamedSymbol.

Returns:
the predicate used in this Atom

getArguments

public final Term[] getArguments()

This function returns the argument Terms of this Atom. These should not be modified as this class cashes the hash value of of the Atom.

Returns:
the arguments of this Atom

isFunctionFree

public boolean isFunctionFree()

This function tests whether this Atom contains any FunctionTerms. This is true only if none of the arguments is a FunctionTerm.

Returns:
true iff this Atom contains no FunctionTerms

isGround

public boolean isGround()

This function tests whether this Atom contains any Variables. This is true only if one of the arguments contains a Variable.

Returns:
true iff this Atom contains no VariableTerms

unify

public boolean unify(Atom other,
                     Substitution s)

This function attempts to extend the given Substitution so that this Atom and the given Atom are unified. It returns true if and only if this is possible. Unification succeeds only if the two predicate symbols are equal and the Substitution can be extended to unify all arguments.

Parameters:
other - the other Atom this Atom 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 int compareTo(Atom other)

This function compares this Atom to the given Atom. The order between Atoms is defined by the order of the predicate symbols and the argument Terms they contain. First the predicate symbols are compared. Next, the first argument Terms are compared and if they are equal the second argument Terms are compared etc. It is like an alphabetical sorting.

Parameters:
other - the Atom to which this Atom is to be compared
Returns:
0 if the two Atoms are identical; -1 if the given Atom should come after this Atom; and +1 if the given Atom should come before this Atom

addConstants

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

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

Specified by:
addConstants in class Sentence
Parameters:
sys - the Set that will contain all the Constants

addFunctions

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

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

Specified by:
addFunctions in class Sentence
Parameters:
sys - the Set that will contain all the function names

addPredicates

protected void addPredicates(java.util.Map<NamedSymbol,java.lang.Integer> sys)

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

Specified by:
addPredicates in class Sentence
Parameters:
sys - the Set that will contain all the predicate names

addFreeVariables

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

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

Specified by:
addFreeVariables in class Sentence
Parameters:
free - a Set of free Variables that will be extended
bound - a Set of bound Variables

addBoundVariables

protected final void addBoundVariables(java.util.Set<Variable> bound)

This function adds the bound Variables in this Sentence to the given Set. This implementation does not modify the given Set.

Specified by:
addBoundVariables in class Sentence
Parameters:
bound - a Set of bound Variables that will be extended

skolemize

protected Sentence skolemize(boolean isNegated,
                             Term[] uqVars,
                             Substitution s)

This function computes a skolemized version of this Sentence. It returns a Literal that has a sign according to the given boolean, the predicate from this Atom, and clones of the arguments under the given Substitution.

Specified by:
skolemize in class Sentence
Parameters:
isNegated - whether the Sentence is negated
uqVars - the known universally quantified Variables at this point
s - the Substitution for Variable replacements
Returns:
a new Sentence with no quantification (can be converted to CNF/DNF)

toCNF

protected Sentence toCNF(boolean isNegated)

This function returns a new Literal which contains the proposition contained in this Atom. The given boolean indicates whether the new Literal is to be negated.

Specified by:
toCNF in class Sentence
Parameters:
isNegated - whether the Literal has to be negated
Returns:
a new Literal, possibly negative

toDNF

protected Sentence toDNF(boolean isNegated)

This function returns a new Literal which contains the proposition contained in this Atom. The given boolean indicates whether the new Literal is to be negated.

Specified by:
toDNF in class Sentence
Parameters:
isNegated - whether the Literal has to be negated
Returns:
a new Literal, possibly negative

toString

public java.lang.String toString()

A Atom is printed as <predicate> ( <Term>+ ).

Overrides:
toString in class java.lang.Object
Returns:
the String that represents this Atom

equals

public boolean equals(java.lang.Object obj)

A Atom is only equal to another Atom.

Overrides:
equals in class java.lang.Object
Parameters:
obj - the Object this Atom is compared to
Returns:
whether the given Object equals this Atom

equals

public boolean equals(Atom other)

A Atom is equal to any other Atom that consists of an equal predicate symbol followed by an equal number of equal Terms.

Parameters:
other - the Object this Atom is compared to
Returns:
whether the given Object equals this Atom

hashCode

public final int hashCode()

This function returns the hash code of this Atom.

Overrides:
hashCode in class java.lang.Object
Returns:
a positive integer that may be used for hashing