ai.krr.propositions
Class Literal

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

public class Literal
extends Sentence

A Literal is one of the most basic building blocks for a Sentence. It simply consists of a signed proposition.

Author:
Gerhard Wickler

Field Summary
protected  boolean sign
          indicates whether this Literal is positive (true) or negative (false)
protected  NamedSymbol theSy
          the proposition symbol
 
Constructor Summary
Literal(boolean sign, NamedSymbol prop)
           This constructor for a Literal takes a NamedSymbol for the proposition and a sign.
 
Method Summary
 void addPropositions(java.util.Set<NamedSymbol> props)
           This function adds the propositions contained in this Sentence to the given Set.
 Literal clone()
           Cloning a Literal returns a new Literal consisting of the same proposition with the same sign.
 int compareTo(Literal other)
           This function compares this Literal to the given Literal.
 int compareTo(Sentence stmt)
           This function compares this Sentence to the given Sentence.
 boolean complements(Literal other)
           This function tests whether this and the given Literal complementary.
 boolean equals(Literal other)
           A Literal is equal to another Literal that consists of an equal sign and proposition symbol.
 boolean equals(java.lang.Object obj)
           A Literal is equal to another Literal that consists of an equal sign and proposition symbol.
 BooleanSymbol evaluate(Interpretation ipt)
           This function evaluates this Sentence under the given Interpretation.
 int getClassOrderIndex()
           This function returns the index used for ordering Sentences across different classes.
 NamedSymbol getSymbol()
           This function returns the Symbol that is the proposition contained in this Literal.
 int hashCode()
           This function returns the hash code of this Literal.
 boolean isLiteral()
           This function tests whether this Sentence is a Literal.
 boolean isPositive()
           This function tests whether this is a positive Literal.
 void negate()
           This function can be used to change the sign of this Literal.
protected  Sentence toCNF(boolean isNegated)
           This function returns a new Literal which is a copy of this Literal.
protected  Sentence toDNF(boolean isNegated)
           This function returns a new Literal which is a copy of this Literal.
 java.lang.String toString()
           A Literal is printed as the sign ('+' or '-') followed by the proposition symbol.
 
Methods inherited from class ai.krr.propositions.Sentence
addSubSentences, allSubSentences, exceedsDepth, getDepth, getPropositions, isAtom, prettyPrint, read, toClauseForm, toCNF, toDNF, write
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

sign

protected boolean sign
indicates whether this Literal is positive (true) or negative (false)


theSy

protected final NamedSymbol theSy
the proposition symbol

Constructor Detail

Literal

public Literal(boolean sign,
               NamedSymbol prop)

This constructor for a Literal takes a NamedSymbol for the proposition and a sign. The given Symbol must not be null.

Parameters:
prop - the proposition symbol
sign - true if and only if this is a positive Literal
Method Detail

clone

public Literal clone()

Cloning a Literal returns a new Literal consisting of the same proposition with the same sign.

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

isLiteral

public final boolean isLiteral()

This function tests whether this Sentence is a Literal.

Overrides:
isLiteral in class Sentence
Returns:
always true

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 Literal the returned truth value is the value of the contained NamedSymbol combined with the sign of this Literal.

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

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

isPositive

public boolean isPositive()

This function tests whether this is a positive Literal.

Returns:
whether this Literal is positive, i.e. not negated

getSymbol

public final NamedSymbol getSymbol()

This function returns the Symbol that is the proposition contained in this Literal.

Returns:
the Symbol that makes up this Literal

negate

public void negate()

This function can be used to change the sign of this Literal.


complements

public boolean complements(Literal other)

This function tests whether this and the given Literal complementary. This will be the case if they have the same proposition symbol, but the signs are different.

Parameters:
other - the Literal this one is to be compared to
Returns:
whether the given Literal is complementary to this one

compareTo

public int compareTo(Literal other)

This function compares this Literal to the given Literal. The order between Literals is primarily defined by the order of the contained propositions. If the Literals are complementary the negative one comes first.

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

toCNF

protected Sentence toCNF(boolean isNegated)

This function returns a new Literal which is a copy of this Literal. The given boolean indicates whether the Literal is to be negated, i.e. its sign to be reversed.

Specified by:
toCNF in class Sentence
Parameters:
isNegated - whether the Literal has to be negated
Returns:
a new Literal with the given boolean worked into the sign

toDNF

protected Sentence toDNF(boolean isNegated)

This function returns a new Literal which is a copy of this Literal. The given boolean indicates whether the Literal is to be negated, i.e. its sign to be reversed.

Specified by:
toDNF in class Sentence
Parameters:
isNegated - whether the Literal has to be negated
Returns:
a new Literal with the given boolean worked into the sign

toString

public java.lang.String toString()

A Literal is printed as the sign ('+' or '-') followed by the proposition symbol.

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

equals

public boolean equals(java.lang.Object obj)

A Literal is equal to another Literal that consists of an equal sign and proposition symbol.

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

equals

public boolean equals(Literal other)

A Literal is equal to another Literal that consists of an equal sign and proposition symbol.

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

hashCode

public int hashCode()

This function returns the hash code of this Literal.

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