ai.krr.propositions
Class BinaryConnectedSentence

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

public class BinaryConnectedSentence
extends ConnectedSentence

This class represents a Sentence that consists of a Connective that connects two sub-Sentences. The Connective that may be given to the public constructor must be IMPLIES, IFF or XOR. ConnectedSentences based on AND or OR must be constructed as ConnectedSentences.

Author:
Gerhard Wickler

Nested Class Summary
 
Nested classes/interfaces inherited from class ai.krr.propositions.ConnectedSentence
ConnectedSentence.Connective
 
Field Summary
 
Fields inherited from class ai.krr.propositions.ConnectedSentence
connective, sentences
 
Constructor Summary
BinaryConnectedSentence(Sentence lhs, ConnectedSentence.Connective connective, Sentence rhs)
           This constructor for a BinaryConnectedSentence takes a Connective and two Sentences which are the Sentences that are connected by the given connective.
 
Method Summary
 void addPropositions(java.util.Set<NamedSymbol> props)
           This function adds the propositions contained in this Sentence to the given Set.
 BinaryConnectedSentence clone()
           This function generates a deep copy of this BinaryConnectedSentence.
 int compareTo(ConnectedSentence other)
           This function compares this BinaryConnectedSentence to the given ConnectedSentence.
 boolean equals(ConnectedSentence other)
           This function tests whether this and the given Object are equal.
 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 getDepth()
           This function returns the nesting depth of this Sentence.
 Sentence getLeftHandSide()
           This function returns the left-hand side sub-Sentence of this BinaryConnectedSentence.
 Sentence getRightHandSide()
           This function returns the right-hand side sub-Sentence of this BinaryConnectedSentence.
 int hashCode()
           This function returns the hash code of this ConnectedSentence.
protected  Sentence toCNF(boolean isNegated)
           This function returns a new Sentence which is the CNF of this Sentence.
protected  Sentence toDNF(boolean isNegated)
           This function returns a new Sentence which is the DNF of this Sentence.
 
Methods inherited from class ai.krr.propositions.ConnectedSentence
compareTo, equals, getClassOrderIndex, getConnective, getSubSentences, isConjunction, isDisjunction, multiplyS, toString
 
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
 

Constructor Detail

BinaryConnectedSentence

public BinaryConnectedSentence(Sentence lhs,
                               ConnectedSentence.Connective connective,
                               Sentence rhs)

This constructor for a BinaryConnectedSentence takes a Connective and two Sentences which are the Sentences that are connected by the given connective. The first Sentence is taken to be the left hand side where that matters. The connective should be IMPLIES, IFF or XOR.

Parameters:
lhs - the left hand side sub-Sentence
connective - the connective (e.g. Connective.AND)
rhs - the right hand side sub-Sentence
Method Detail

clone

public BinaryConnectedSentence clone()

This function generates a deep copy of this BinaryConnectedSentence. The copy will contain the same Symbols as the original.

Overrides:
clone in class ConnectedSentence
Returns:
an equal copy of this BinaryConnectedSentence

getDepth

public int getDepth()

This function returns the nesting depth of this Sentence. The depth of a implication is the maximum depth of the sub-Sentences plus 1. The depth of a co-implication or exclusive disjunction is the maximum depth of the sub-Sentences plus 2.

Overrides:
getDepth in class ConnectedSentence
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 ConnectedSentence
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.

Overrides:
addPropositions in class ConnectedSentence
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 may be null, indicating the truth value of this Sentence is undefined under the given Interpretation. For a BinaryConnectedSentence the returned truth value depends on the connective. It will be BooleanSymbol.TRUE iff:

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

getLeftHandSide

public final Sentence getLeftHandSide()

This function returns the left-hand side sub-Sentence of this BinaryConnectedSentence. This could be for example, the premise of an implication.

Returns:
the first sub-Sentence connected here

getRightHandSide

public final Sentence getRightHandSide()

This function returns the right-hand side sub-Sentence of this BinaryConnectedSentence. This could be for example, the conclusion of an implication.

Returns:
the second sub-Sentence connected here

compareTo

public int compareTo(ConnectedSentence other)

This function compares this BinaryConnectedSentence to the given ConnectedSentence. The order between ConnectedSentences is primarily defined by the order of the Connectives they contain. If they use the same connective a lexical ordering is used, i.e. first the first sub-Sentences are compared. If they are different this determines the overall result, otherwise the second sub-Sentences are compared, etc.

Overrides:
compareTo in class ConnectedSentence
Parameters:
other - the ConnectedSentence to which this BinaryConnectedSentence 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 Sentence which is the CNF of this Sentence. The given boolean indicates whether the Sentence is to be treated as negated at this point.

Overrides:
toCNF in class ConnectedSentence
Parameters:
isNegated - whether the Sentence is negated
Returns:
a new Sentence which is the CNF of this Sentence, possibly negated

toDNF

protected Sentence toDNF(boolean isNegated)

This function returns a new Sentence which is the DNF of this Sentence. The given boolean indicates whether the Sentence is to be treated as negated at this point.

Overrides:
toDNF in class ConnectedSentence
Parameters:
isNegated - whether the Sentence is negated
Returns:
a new Sentence which is the DNF of this Sentence, possibly negated

equals

public boolean equals(ConnectedSentence other)

This function tests whether this and the given Object are equal. In general, two ConnectedSentences are equal if they have the same connective and all the sub-Sentences are in the same order and equal.

Overrides:
equals in class ConnectedSentence
Parameters:
other - the Sentence this one is to be compared to
Returns:
whether the given Object is equal to this one

hashCode

public int hashCode()

This function returns the hash code of this ConnectedSentence.

Overrides:
hashCode in class ConnectedSentence
Returns:
a positive integer that may be used for hashing