ai.krr.propositions
Class ConnectedSentence

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

public class ConnectedSentence
extends Sentence

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

Author:
Gerhard Wickler

Nested Class Summary
static class ConnectedSentence.Connective
           This enumeration defines the possible connectives that can connect the sub-Sentences.
 
Field Summary
protected  ConnectedSentence.Connective connective
          the connective for this Sentence
protected  Sentence[] sentences
          the sub-Sentences connected here
 
Constructor Summary
  ConnectedSentence(ConnectedSentence.Connective connective, java.util.Collection<Sentence> sents)
           This constructor for a ConnectedSentence takes a Connective and a List of Sentences which are the Sentences that are connected by the given connective.
  ConnectedSentence(ConnectedSentence.Connective connective, Sentence... sentences)
           This constructor for a ConnectedSentence takes a Connective and a number of Sentences which are the Sentences that are connected by the given connective.
protected ConnectedSentence(Sentence s1, ConnectedSentence.Connective connective, Sentence s2)
           This constructor for a ConnectedSentence 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.
 ConnectedSentence clone()
           This function generates a shallow copy of this ConnectedSentence.
 int compareTo(ConnectedSentence other)
           This function compares this ConnectedSentence to the given ConnectedSentence.
 int compareTo(Sentence stmt)
           This function compares this Sentence to the given Sentence.
 boolean equals(ConnectedSentence other)
           This function tests whether this and the given Object are equal.
 boolean equals(java.lang.Object obj)
           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 getClassOrderIndex()
           This function returns the index used for ordering Sentences across different classes.
 ConnectedSentence.Connective getConnective()
           This function returns the Connective that connects the sub-Sentences in this ConnectedSentence.
 int getDepth()
           This function returns the nesting depth of this Sentence.
 Sentence[] getSubSentences()
           This function returns the the sub-Sentences that are joined in this ConnectedSentence.
 int hashCode()
           This function returns the hash code of this ConnectedSentence.
 boolean isConjunction()
           This function tests whether this Sentence is a conjunction.
 boolean isDisjunction()
           This function tests whether this Sentence is a disjunction.
(package private) static java.util.List<java.util.List<Literal>> multiplyS(java.util.List<java.util.List<Literal>> nf, ConnectedSentence lits)
          This function multiplies the given List of List of Literals with the given ConnectedSentence.
protected  Sentence toCNF(boolean isNegated)
           This function returns a new Sentence which is the CNF form of this ConnectedSentence.
protected  Sentence toDNF(boolean isNegated)
           This function returns a new Sentence which is the CNF form of this AndOrSentence.
 java.lang.String toString()
           A ConnectedSentence is printed as:
 
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

connective

protected final ConnectedSentence.Connective connective
the connective for this Sentence


sentences

protected final Sentence[] sentences
the sub-Sentences connected here

Constructor Detail

ConnectedSentence

public ConnectedSentence(ConnectedSentence.Connective connective,
                         java.util.Collection<Sentence> sents)

This constructor for a ConnectedSentence takes a Connective and a List of Sentences which are the Sentences that are connected by the given connective. The connective should be AND or OR.

Parameters:
connective - the connective (e.g. Connective.AND)
sents - the Sentences to be connected here

ConnectedSentence

public ConnectedSentence(ConnectedSentence.Connective connective,
                         Sentence... sentences)

This constructor for a ConnectedSentence takes a Connective and a number of Sentences which are the Sentences that are connected by the given connective. The connective should be AND or OR.

Parameters:
connective - the connective (e.g. Connective.AND)
sentences - the Sentences to be connected here

ConnectedSentence

protected ConnectedSentence(Sentence s1,
                            ConnectedSentence.Connective connective,
                            Sentence s2)

This constructor for a ConnectedSentence takes a Connective and two Sentences which are the Sentences that are connected by the given connective.

Parameters:
connective - the connective (e.g. Connective.XOR)
s1 - the first Sentence to be connected here
s2 - the second Sentence to be connected here
Method Detail

clone

public ConnectedSentence clone()

This function generates a shallow copy of this ConnectedSentence. The copy will contain the same sub-Sentences as the original.

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

getDepth

public int getDepth()

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

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

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

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

getConnective

public final ConnectedSentence.Connective getConnective()

This function returns the Connective that connects the sub-Sentences in this ConnectedSentence.

Returns:
the Connective of this ConnectedSentence

getSubSentences

public final Sentence[] getSubSentences()

This function returns the the sub-Sentences that are joined in this ConnectedSentence.

Returns:
the sub-Sentences of this ConnectedSentence

isConjunction

public boolean isConjunction()

This function tests whether this Sentence is a conjunction.

Returns:
whether this Sentence is a conjunction

isDisjunction

public boolean isDisjunction()

This function tests whether this Sentence is a disjunction.

Returns:
whether this Sentence is a disjunction

compareTo

public int compareTo(ConnectedSentence other)

This function compares this ConnectedSentence to the given ConnectedSentence. The order between ConnectedSentence 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.

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

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

toDNF

protected Sentence toDNF(boolean isNegated)

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

Specified by:
toDNF in class Sentence
Parameters:
isNegated - whether the Sentence is negated
Returns:
a new AndOrSentence which is the DNF of this Sentence

toString

public java.lang.String toString()

A ConnectedSentence is printed as:

 ( <connective> <formula>+ )
 

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

equals

public boolean equals(java.lang.Object obj)

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 java.lang.Object
Parameters:
obj - the Sentence this one is to be compared to
Returns:
whether the given Object is equal to this one

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.

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 java.lang.Object
Returns:
a positive integer that may be used for hashing

multiplyS

static java.util.List<java.util.List<Literal>> multiplyS(java.util.List<java.util.List<Literal>> nf,
                                                         ConnectedSentence lits)

This function multiplies the given List of List of Literals with the given ConnectedSentence.

Multiplication here is defined as follows: Given a ConnectedSentence of n Literals, the result will contain n times the number of sub-Lists it contained previously, and each copy will be extended with a different Literal from the given ConnectedSentence. For example, multiplying

 ((+A1 +A2) (+B1 +B2))
 

with (AND +C, +D) will result in:

 ((+A1 +A2 +C) (+A1 +A2 +D) (+B1 +B2 +C) (+B1 +B2 +D))
 

Parameters:
lits - a Collection of Literals to multiply this AndOrSentence with