edu.cs.ai.kreator.logic
Class Clause

java.lang.Object
  extended by edu.cs.ai.kreator.logic.Clause
All Implemented Interfaces:
Latexable

public class Clause
extends java.lang.Object
implements Latexable

This class models a clause in clausal logic, i.e., a formula of the form "A <- A1,...,Ak" with A,A1,...,Ak being literals.

Author:
Matthias Thimm, Max Vorderstemann

Field Summary
static org.apache.log4j.Logger LOG
           
 
Constructor Summary
Clause(Literal head, java.util.Collection<? extends Literal> body, VariableFactory factory)
          Constructs a clause with the given head and body.
Clause(Literal head, VariableFactory factory)
          Constructs a clause with the given head and empty body.
 
Method Summary
 boolean containsNegation()
          Checks whether this clause contains any literals with negation in the body.
 boolean equals(java.lang.Object obj)
           
 java.util.Set<Clause> generalize()
          Computes the nearest neighbors of this clause wrt. to generalization, e.g.
 java.util.Set<GeneralizedAtom> getAllAtoms()
          Returns a set of all (generalized) atoms of this clause (occurring in head and body)
 java.util.Set<Constant> getAllConstants()
          Returns all Constant which occurr in this RmeConditional.
 java.util.Set<Literal> getAllLiterals()
          Returns all Literals occurring in this conditional (in head and body).
 java.util.Set<GeneralizedPredicate> getAllPredicates()
          Returns a Set of all predicates of this clause (occurring in head and body)
 java.util.List<Literal> getBody()
           
 java.util.Set<Literal> getDerivations(java.util.Collection<? extends Literal> data, LanguageFactory language)
          Computes the set of derivations possible from the give data using this clause, i.e. if this clause is (B(X)|A(X)) and {A(c1),...
 Literal getHead()
           
 VariableFactory getVariables()
           
 int hashCode()
           
 boolean isFact()
          Returns true, if this clause is a fact, i.e., if its body is empty.
 boolean isGround()
          Checks whether this clause is ground, i.e.
 boolean isLogicallyValid(java.util.Collection<? extends Literal> data, LanguageFactory language)
          Checks whether this clause is logically valid wrt. to the given data, i.e.
 boolean mentions(GeneralizedPredicate p)
          Checks whether the given predicate is mentioned in this clause.
static int numberOfConnections(java.util.Collection<? extends Clause> clauses)
          This method computes the number of connections between the given clauses.
 java.util.Set<Clause> specialize(LanguageFactory language)
          Computes the nearest neighbors of this clause wrt. to specialization, e.g.
 java.lang.String toLatex()
          Returns a Latex grammar conform string to generate variables, rules (conditionals) etc.
 java.lang.String toString()
           
 java.util.Set<Clause> unify(Literal literal, LanguageFactory language)
          This method tries to unify this clause's head with the given literal and returns all possible clauses where all variables are substituted according to this unification and all other possible substitutions.
 java.util.Set<Clause> unify(Literal literal, LanguageFactory language, java.util.Map<Sort,java.util.Set<Constant>> additionalConstants)
          This method tries to unify this clause's head with the given literal and returns all possible clauses where all variables are substituted according to this unification and all other possible substitutions.
 Clause unifyPartially(Literal literal)
          This method tries to unify this clause's head with the given literal and returns a partially substituted clause.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

LOG

public static final org.apache.log4j.Logger LOG
Constructor Detail

Clause

public Clause(Literal head,
              VariableFactory factory)
       throws InvalidLanguageExpressionException
Constructs a clause with the given head and empty body.

Parameters:
head - a literal
Throws:
InvalidLanguageExpressionException - if the given head cannot be represented using the given variables.

Clause

public Clause(Literal head,
              java.util.Collection<? extends Literal> body,
              VariableFactory factory)
       throws InvalidLanguageExpressionException
Constructs a clause with the given head and body.

Parameters:
head - a literal
body - a list of literals
Throws:
InvalidLanguageExpressionException - if the clause cannot be represented using the given variables.
Method Detail

isGround

public boolean isGround()
Checks whether this clause is ground, i.e. whether it contains no variables.

Returns:
"true" if this clause is ground.

numberOfConnections

public static int numberOfConnections(java.util.Collection<? extends Clause> clauses)
This method computes the number of connections between the given clauses. Two clauses c1 and c2 are connected if they share a predicate.

Parameters:
clauses - a collection of clauses.
Returns:
an integer >= 0 referring to the number of connections.

unifyPartially

public Clause unifyPartially(Literal literal)
This method tries to unify this clause's head with the given literal and returns a partially substituted clause. For example, given the atom "alarm(james)" and the clause "alarm(X) | lives_in(X,Y), tornado(Y)." this method returns "alarm(james) | lives_in(james,Y), tornado(Y)"

Parameters:
literal - a literal
Returns:
a clause if the head of this clause can be unified with literal, "null" otherwise.

unify

public java.util.Set<Clause> unify(Literal literal,
                                   LanguageFactory language)
This method tries to unify this clause's head with the given literal and returns all possible clauses where all variables are substituted according to this unification and all other possible substitutions. For example, given the literal "alarm(james)" and the clause "alarm(X) | lives_in(X,Y), tornado(Y)." this method returns the set "{alarm(james) | lives_in(james,c), tornado(c) || c is a constant}"

Parameters:
literal - a literal
language - a LanguageFactory
Returns:
a set of bayesian clauses if the head of this clause can be unified with literal, "null" otherwise.

unify

public java.util.Set<Clause> unify(Literal literal,
                                   LanguageFactory language,
                                   java.util.Map<Sort,java.util.Set<Constant>> additionalConstants)
This method tries to unify this clause's head with the given literal and returns all possible clauses where all variables are substituted according to this unification and all other possible substitutions. For example, given the literal "alarm(james)" and the clause "alarm(X) | lives_in(X,Y), tornado(Y)." this method returns the set "{alarm(james) | lives_in(james,c), tornado(c) || c is a constant}"

Parameters:
literal - a literal
language - a LanguageFactory
additionalConstants - a set of additional constants to be considered when unifying.
Returns:
a set of bayesian clauses if the head of this clause can be unified with literal, "null" otherwise.

isLogicallyValid

public boolean isLogicallyValid(java.util.Collection<? extends Literal> data,
                                LanguageFactory language)
Checks whether this clause is logically valid wrt. to the given data, i.e. whether for this clause (B(X)|A(X)) it holds: if A(c) in data (for some constant(s) c) then B(c) in data.

Parameters:
data - a list of literals.
language - the language of the data.
Returns:
"true" if this clause is logically valid wrt. the given data.

getDerivations

public java.util.Set<Literal> getDerivations(java.util.Collection<? extends Literal> data,
                                             LanguageFactory language)
Computes the set of derivations possible from the give data using this clause, i.e. if this clause is (B(X)|A(X)) and {A(c1),...,A(cn)} is in data then this method returns {B(c1),...,B(cn)}.

Parameters:
data - a list of literals.
language - the language of the data.
Returns:
a set of atoms.

generalize

public java.util.Set<Clause> generalize()
Computes the nearest neighbors of this clause wrt. to generalization, e.g. the clause (a|b,c) has the generalizations (a|b) and (a|c).

Returns:
the set of generalized clauses of this clause.

specialize

public java.util.Set<Clause> specialize(LanguageFactory language)
Computes the nearest neighbors of this clause wrt. to specialization, e.g. the clause (a|b) has the specializations (a|b,c) and (a|b,d), given that {c,d} is the whole set of remaining predicates.

Parameters:
language - a language
Returns:
the set of specialized clauses of this clause.

containsNegation

public boolean containsNegation()
Checks whether this clause contains any literals with negation in the body.

Returns:
"true" iff this clause contains a literal with negation in the body.

mentions

public boolean mentions(GeneralizedPredicate p)
Checks whether the given predicate is mentioned in this clause.

Parameters:
l - a bayesian predicate.
Returns:
"true" iff the predicate is mentioned in this clause.

isFact

public boolean isFact()
Returns true, if this clause is a fact, i.e., if its body is empty.

Returns:
a boolean; true, if this clause is a fact, i.e., if its body is empty.

getHead

public Literal getHead()

getBody

public java.util.List<Literal> getBody()

getVariables

public VariableFactory getVariables()

getAllPredicates

public java.util.Set<GeneralizedPredicate> getAllPredicates()
Returns a Set of all predicates of this clause (occurring in head and body)

Returns:
a Set of all predicates of this clause (occurring in head and body)

getAllAtoms

public java.util.Set<GeneralizedAtom> getAllAtoms()
Returns a set of all (generalized) atoms of this clause (occurring in head and body)

Returns:
a set of all (generalized) atoms of this clause (occurring in head and body)

getAllLiterals

public java.util.Set<Literal> getAllLiterals()
Returns all Literals occurring in this conditional (in head and body).

Returns:
all Literals occurring in this conditional.

getAllConstants

public java.util.Set<Constant> getAllConstants()
Returns all Constant which occurr in this RmeConditional.

Returns:
the constants.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

toLatex

public java.lang.String toLatex()
Description copied from interface: Latexable
Returns a Latex grammar conform string to generate variables, rules (conditionals) etc.

Specified by:
toLatex in interface Latexable
Returns:
a Latex grammar conform string.

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object