|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectai.krr.propositions.Sentence
public abstract class Sentence
A Sentence is usually used in logic to represent a proposition that is either true or false. More formally, a Sentence in propositional logic is a syntactic expression that has a truth value under a given interpretation. Currently, there are several kinds of Sentence implemented.
Constructor Summary | |
---|---|
Sentence()
|
Method Summary | |
---|---|
abstract void |
addPropositions(java.util.Set<NamedSymbol> props)
This function adds the propositions contained in this Sentence to the given Set. |
protected void |
addSubSentences(java.util.List<Sentence> sents,
boolean rootFirst)
This function can be used to fill the given List of with all the sub-Sentences of this Sentence, including the Sentence itself. |
java.util.List<Sentence> |
allSubSentences(boolean rootFirst)
This function can be used to create a List of all the sub-Sentences of this Sentence, including the Sentence itself. |
abstract Sentence |
clone()
This function generates a deep copy of this Sentence. |
abstract int |
compareTo(Sentence stmt)
This function compares this Sentence to the given Sentence. |
abstract BooleanSymbol |
evaluate(Interpretation i)
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. |
abstract 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. |
java.util.Set<NamedSymbol> |
getPropositions()
This function returns the set of propositional symbols that occur in this Sentence. |
boolean |
isAtom()
This function tests whether this Sentence is an Atom. |
boolean |
isLiteral()
This function tests whether this Sentence is a Literal. |
void |
prettyPrint(int indent,
java.io.Writer w,
inf.compilers.SyntaxAdaptor sa)
This function can be used write this SyntaxAdaptable object to the given Writer. |
static Sentence |
read(java.io.Reader r,
inf.compilers.SyntaxAdaptor<Sentence> sa)
|
java.util.List<Clause> |
toClauseForm()
This function converts this Sentence into an equivalent set of Clauses. |
Sentence |
toCNF()
This function returns a new Sentence which is the CNF of this Sentence. |
protected abstract Sentence |
toCNF(boolean isNegated)
This function returns a new Sentence which is the CNF of this Sentence. |
Sentence |
toDNF()
This function returns a new Sentence which is the DNF of this Sentence. |
protected abstract Sentence |
toDNF(boolean isNegated)
This function returns a new Sentence which is the DNF of this Sentence. |
void |
write(java.io.Writer w,
inf.compilers.SyntaxAdaptor sa)
This function can be used write this logical Sentence to the given Writer. |
Methods inherited from class java.lang.Object |
---|
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Sentence()
Method Detail |
---|
public abstract Sentence clone()
This function generates a deep copy of this Sentence. The copy will contain the same Symbols as the original.
clone
in class java.lang.Object
public abstract 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.
compareTo
in interface java.lang.Comparable<Sentence>
stmt
- the Sentence to which this Sentence is to be compared
public abstract int getClassOrderIndex()
This function returns the index used for ordering Sentences across different classes.
public abstract void addPropositions(java.util.Set<NamedSymbol> props)
This function adds the propositions contained in this Sentence to the given Set. The boolean propositions TRUE and FALSE will not be added to the set.
props
- the Set to which the propositional symbols are addedpublic abstract BooleanSymbol evaluate(Interpretation i)
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.
i
- the Interpretation giving truth values for propositions
public boolean isAtom()
This function tests whether this Sentence is an Atom. This default implementation always returns false. /p>
public boolean isLiteral()
This function tests whether this Sentence is a Literal. This default implementation always returns false.
public int getDepth()
This function returns the nesting depth of this Sentence. The depth of a TruthValue, an Atom or a Literal is defined to be 0. The depth of a negated sentence is the depth of the contained Sentence. The depth of a conjunction, disjunction, or 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. This default implementation returns 0.
public boolean exceedsDepth(int depth)
This function tests whether this Sentence exceeds the given depth which should be a non-negative integer. The default implementation provided here returns whether the given integer is negative.
depth
- the depth value that is tested for
public java.util.Set<NamedSymbol> getPropositions()
This function returns the set of propositional symbols that occur in this Sentence. The boolean propositions TRUE and FALSE will not be contained in the result.
public Sentence toCNF()
This function returns a new Sentence which is the CNF of this Sentence. This is done by:
public Sentence toDNF()
This function returns a new Sentence which is the DNF of this Sentence. This is done by:
public java.util.List<Clause> toClauseForm()
This function converts this Sentence into an equivalent set of Clauses. To achieve this, this Sentence is first converted to CNF. If this results in TruthValue.TRUE, an empty set will be returned. If this results in TruthValue.FALSE, the returned Set will contain exactly one Clause which will be the empty Clause. Otherwise the returned Set will contain at least one Clause and none of the returned Clauses will be empty.
public void write(java.io.Writer w, inf.compilers.SyntaxAdaptor sa) throws inf.compilers.ExpressivenessException, java.io.IOException
This function can be used write this logical Sentence to the given Writer. The syntax in which it is written is defined by the SyntaxAdaptor that is also given to this function.
write
in interface inf.compilers.SyntaxAdaptable
w
- the Writer to which this Sentence is writtensa
- the SyntaxAdaptor that determines the syntax
inf.compilers.ExpressivenessException
- if the syntax does not support every
construct occurring in this Sentence
java.io.IOException
- if writing to the Writer failspublic void prettyPrint(int indent, java.io.Writer w, inf.compilers.SyntaxAdaptor sa) throws inf.compilers.ExpressivenessException, java.io.IOException
This function can be used write this SyntaxAdaptable object to the given Writer. The syntax is the same as for normal writing. The only difference is the inclusion of extra space and newlines for better readability.
prettyPrint
in interface inf.compilers.SyntaxAdaptable
indent
- the amount of indentation for the first linew
- the Writer to which this Sentence is writtensa
- the SyntaxAdaptor that determines the syntax
inf.compilers.ExpressivenessException
- if the syntax does not support every
construct occurring in this Sentence
java.io.IOException
- if writing to the Writer failspublic java.util.List<Sentence> allSubSentences(boolean rootFirst)
This function can be used to create a List of all the sub-Sentences of
this Sentence, including the Sentence itself. If the given boolean is
true, a Sentence will preceed its sub-Sentences, otherwise it will
succeed them. For a shallow Iterator over a ConnectedSentence see
ConnectedSentence.sentences
.
rootFirst
- true means Sentence before its sub-Sentences
protected abstract 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.
isNegated
- whether the Sentence is negated
protected abstract 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.
isNegated
- whether the Sentence is negated
protected void addSubSentences(java.util.List<Sentence> sents, boolean rootFirst)
This function can be used to fill the given List of with all the sub-Sentences of this Sentence, including the Sentence itself. If the given boolean is true, a Sentence will preceed its sub-Sentences, otherwise it will succeed them. This function performs a complete traversal of this Sentence as a tree, down to the level of Literals, Atoms and TruthValues.
sents
- the List to add the sub-Sentences torootFirst
- true means Sentence before its sub-Sentencespublic static Sentence read(java.io.Reader r, inf.compilers.SyntaxAdaptor<Sentence> sa) throws inf.compilers.ExpressivenessException, java.text.ParseException, java.io.IOException
inf.compilers.ExpressivenessException
java.text.ParseException
java.io.IOException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |