ai.krr.fol
Class Clause

java.lang.Object
  extended by ai.krr.fol.Clause
All Implemented Interfaces:
java.lang.Cloneable, java.lang.Comparable<Clause>

public class Clause
extends java.lang.Object
implements java.lang.Cloneable, java.lang.Comparable<Clause>


Field Summary
protected  Literal[] literals
          the Literals of this Clause
 
Constructor Summary
Clause(java.util.Collection<Literal> lits)
           This constructor for a Clause takes a List of Literals.
Clause(Literal... lits)
           This constructor for a Clause takes an Array of Literals.
 
Method Summary
protected  Clause clone()
           This function generates a shallow copy of this Clause.
 int compareTo(Clause other)
           This function compares this Clause to the given Clause.
 boolean contains(Literal literal)
           This function tests whether the given Literal is contained in this Clause.
 boolean equals(Clause other)
           This function tests whether this and the given Clause are equal.
 boolean equals(java.lang.Object obj)
           This function tests whether this and the given Object are equal.
 BooleanSymbol evaluate(Interpretation ipt, Substitution s)
           This function evaluates this Sentence under the given Interpretation.
 java.util.Set<Symbol> getConstants()
           This function returns a set of all the constant Symbols occurring in this Clause.
 java.util.Map<Symbol,java.lang.Integer> getFunctions()
           This function returns a set of all the function Symbols occurring in this Clause.
 Literal[] getLiterals()
           This function returns the the Literals that are joined in this Clause.
 java.util.Map<NamedSymbol,java.lang.Integer> getPredicates()
           This function returns a set of all the predicate Symbols occurring in this Clause.
 java.util.Set<Variable> getVariables()
           This function adds all the Variables in this Clause to the returned Set.
 int hashCode()
           This function returns the hash code of this Clause.
 int size()
           This function returns the number of Literals in this Clause.
 Sentence toSentence()
           This function converts this Clause to an ordinary first-order Sentence, which is either TruthValue.FALSE for the empty Clause, a Literal for a unit Clause, or a disjunction of the Literals in this Clause.
 java.lang.String toString()
           A Clause is printed as:
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

literals

protected final Literal[] literals
the Literals of this Clause

Constructor Detail

Clause

public Clause(java.util.Collection<Literal> lits)

This constructor for a Clause takes a List of Literals. Internally, the Literals are stored in a sorted order, resulting in a time complexity of O(n log(n)) for this constructor.

Parameters:
lits - the Literals to be connected here

Clause

public Clause(Literal... lits)

This constructor for a Clause takes an Array of Literals. Internally, the Literals are stored in a sorted order, resulting in a time complexity of O(n log(n)) for this constructor.

Parameters:
lits - the Literals to be connected here
Method Detail

clone

protected Clause clone()

This function generates a shallow copy of this Clause. The copy will contain the same Literals as the original.

Overrides:
clone in class java.lang.Object
Returns:
an equal copy of this Clause

compareTo

public int compareTo(Clause other)

This function compares this Clause to the given Clause. The order between Clauses is primarily determined by their length: shorter Clauses come first. The order between Clauses of equal length is a lexical ordering, i.e. first the first Literals are compared. If they are different this determines the overall result, otherwise the second Literals are compared, etc. Note that Literals are not considered in the order given to the constructor, but in their natural order.

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

getLiterals

public final Literal[] getLiterals()

This function returns the the Literals that are joined in this Clause.

Returns:
the Literals of this Clause

size

public int size()

This function returns the number of Literals in this Clause.

Returns:
the number of Literals in this Clause

contains

public boolean contains(Literal literal)

This function tests whether the given Literal is contained in this Clause.

Parameters:
literal - the Literal to be tested for
Returns:
whether lit is in this Clause

getConstants

public java.util.Set<Symbol> getConstants()

This function returns a set of all the constant Symbols occurring in this Clause.

Returns:
a Set of all the constant Symbols in this Sentence

getVariables

public java.util.Set<Variable> getVariables()

This function adds all the Variables in this Clause to the returned Set.

Returns:
a Set containing all free Variables occurring in this Sentence

getFunctions

public java.util.Map<Symbol,java.lang.Integer> getFunctions()

This function returns a set of all the function Symbols occurring in this Clause. Each function is mapped to its arity.

Returns:
a Set of all the function Symbols in this Sentence

getPredicates

public java.util.Map<NamedSymbol,java.lang.Integer> getPredicates()

This function returns a set of all the predicate Symbols occurring in this Clause.

Returns:
a Set of all the predicate Symbols in this Sentence

toSentence

public Sentence toSentence()

This function converts this Clause to an ordinary first-order Sentence, which is either TruthValue.FALSE for the empty Clause, a Literal for a unit Clause, or a disjunction of the Literals in this Clause.

Returns:
this Clause as a Sentence

evaluate

public BooleanSymbol evaluate(Interpretation ipt,
                              Substitution s)

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:

Parameters:
ipt - the Interpretation giving truth values for propositions
Returns:
the truth value of this Sentence under the given Interpretation

toString

public java.lang.String toString()

A Clause is printed as:

 ( <literal>+ )
 

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

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 Object this one is to be compared to
Returns:
whether the given Object is equal to this one

equals

public boolean equals(Clause other)

This function tests whether this and the given Clause are equal. In general, two Clauses are equal if they contain equal Literals, where the order of the Literals is not relevant.

Parameters:
other - the Clause this one is to be compared to
Returns:
whether the given Object is equal to this one

hashCode

public final int hashCode()

This function returns the hash code of this Clause.

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