ai.krr.propositions
Class NegatedSentence

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

public class NegatedSentence
extends Sentence

A NegatedSentence is the simplest kind of complex Sentence. It simply contains the Sentence that is negated. Note that a negated Atom can also be represented as a Literal, but a negative Literal is not equal to a negated sentence containing the same Atom or NamedSymbol.

Author:
Gerhard Wickler

Field Summary
protected  Sentence contained
          the contained Sentence that is negated *
 
Constructor Summary
NegatedSentence(Sentence stmt)
           This constructor for a NegatedSentence simply takes the Sentence that is negated.
 
Method Summary
 void addPropositions(java.util.Set<NamedSymbol> props)
           This function adds the propositions contained in this Sentence to the given Set.
 NegatedSentence clone()
           Cloning a NegatedSentence returns a new NegatedSentence containing the same Sentence as the original.
 int compareTo(NegatedSentence other)
           This function compares this NegatedSentence to the given NegatedSentence.
 int compareTo(Sentence stmt)
           This function compares this Sentence to the given Sentence.
 boolean equals(NegatedSentence other)
           A NegatedSentence is equal to another NegatedSentence that contains an equal Sentence.
 boolean equals(java.lang.Object obj)
           A NegatedSentence is equal to another NegatedSentence that contains an equal Sentence.
 BooleanSymbol evaluate(Interpretation ipt)
           This function evaluates this Sentence under the given Interpretation.
 boolean exceedsDepth(int depth)
           This function tests whether this Sentence exceeds the given depth which should be a non-negative integer.
 int getClassOrderIndex()
           This function returns the index used for ordering Sentences across different classes.
 Sentence getContainedSentence()
           This function returns the Sentence that is contained in this NegatedSentence.
 int getDepth()
           This function returns the nesting depth of this Sentence.
 int hashCode()
          This function returns the hash code of this NegatedSentence.
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 NegatedSentence is printed as the tilde symbol '~' followed by the contained Sentence.
 
Methods inherited from class ai.krr.propositions.Sentence
addSubSentences, allSubSentences, getPropositions, isAtom, isLiteral, prettyPrint, read, toClauseForm, toCNF, toDNF, write
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

contained

protected final Sentence contained
the contained Sentence that is negated *

Constructor Detail

NegatedSentence

public NegatedSentence(Sentence stmt)

This constructor for a NegatedSentence simply takes the Sentence that is negated. The given Sentence must not be null.

Parameters:
stmt - the negated Sentence
Method Detail

clone

public NegatedSentence clone()

Cloning a NegatedSentence returns a new NegatedSentence containing the same Sentence as the original.

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

getDepth

public int getDepth()

This function returns the nesting depth of this Sentence. The depth of a negated sentence is equal to the depth of the contained Sentence.

Overrides:
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.

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

addPropositions

public void addPropositions(java.util.Set<NamedSymbol> props)

This function adds the propositions contained in this Sentence to the given Set. Of course, the given Set must not be null.

Specified by:
addPropositions in class Sentence
Parameters:
props - the Set to which the NamedSymbols are added

evaluate

public BooleanSymbol evaluate(Interpretation ipt)

This function evaluates this Sentence under the given Interpretation. If all propositions occurring in the Sentence have a truth value assigned by the Interpretation the result will be either BooleanSymbol.TRUE or BooleanSymbol.FALSE. Otherwise the result will be null, indicating the truth value of this Sentence is undefined under the given Interpretation. For a NegatedSentence the returned truth value is the negation of the value of the contained Sentence.

Specified by:
evaluate in class Sentence
Parameters:
ipt - the Interpretation giving truth values for propositions
Returns:
the truth value of this Sentence under the given Interpretation

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 3.

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 stmt)

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

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

getContainedSentence

public final Sentence getContainedSentence()

This function returns the Sentence that is contained in this NegatedSentence.

Returns:
the Sentence that is negated here

compareTo

public int compareTo(NegatedSentence other)

This function compares this NegatedSentence to the given NegatedSentence. The order between NegatedSentences is defined by the order of the Sentences they contain.

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

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 NegatedSentence is printed as the tilde symbol '~' followed by the contained Sentence.

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

equals

public boolean equals(java.lang.Object obj)

A NegatedSentence is equal to another NegatedSentence that contains an equal Sentence.

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

equals

public boolean equals(NegatedSentence other)

A NegatedSentence is equal to another NegatedSentence that contains an equal Sentence.

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

hashCode

public int hashCode()

This function returns the hash code of this NegatedSentence.

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