edu.cs.ai.kreator.logic.prolog
Class PrologProgram

java.lang.Object
  extended by edu.cs.ai.kreator.logic.prolog.PrologProgram

public class PrologProgram
extends java.lang.Object

This class models a program in Prolog.

Author:
Matthias Thimm

Constructor Summary
PrologProgram(LanguageFactory language)
          Constructs a prolog program without clauses and with empty universe.
PrologProgram(java.util.Set<Clause> clauses, LanguageFactory language)
          Constructs a prolog program with the given clauses and language.
 
Method Summary
 void addClause(Clause clause)
          Adds the given clause to this prolog program.
 java.util.List<AtomExpression> closure(java.util.List<AtomExpression> data, LanguageFactory language)
          Computes the closure of the given list of atom expression, e.g.
 java.util.Set<Clause> getClauses()
          Returns the clauses of this program.
 java.util.Set<Clause> getClauses(GeneralizedAtom atom)
          Returns the set of (instantiated) clauses where the head unifies with given bayesian atom.
 java.util.Set<Clause> getClauses(GeneralizedAtom atom, java.util.Map<Sort,java.util.Set<Constant>> constants)
          Returns the set of (instantiated) clauses where the head unifies with given bayesian atom.
 LanguageFactory getLanguage()
           
 java.lang.String isEntailed(GeneralizedAtom atom)
          Checks whether the given atom is entailed by this prolog program.
 java.lang.String isEntailed(GeneralizedAtom atom, java.util.List<AtomExpression> evidences)
          Checks whether the given atom is entailed by this prolog program.
 boolean mentions(GeneralizedPredicate p)
          Checks whether the given predicate is mentioned in this program.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

PrologProgram

public PrologProgram(LanguageFactory language)
Constructs a prolog program without clauses and with empty universe.

Parameters:
language - a LanguageFactory.

PrologProgram

public PrologProgram(java.util.Set<Clause> clauses,
                     LanguageFactory language)
              throws InvalidLanguageExpressionException
Constructs a prolog program with the given clauses and language. If the given language does not contain the predicate "=" it is added.

Parameters:
clauses - a set of bayesian clauses
language - a LanguageFactory.
Throws:
InvalidLanguageExpressionException - if the given clauses do not conform to the given language.
Method Detail

addClause

public void addClause(Clause clause)
               throws InvalidLanguageExpressionException
Adds the given clause to this prolog program.

Parameters:
clause - a bayesian clause;
Throws:
InvalidLanguageExpressionException - if the given clause does not conform to the given language.

getClauses

public java.util.Set<Clause> getClauses(GeneralizedAtom atom,
                                        java.util.Map<Sort,java.util.Set<Constant>> constants)
Returns the set of (instantiated) clauses where the head unifies with given bayesian atom. (Also consider the additional constants when instantiating)

Parameters:
atom - a bayesian atom.
constants - a set of bayesian clauses.
Returns:

getClauses

public java.util.Set<Clause> getClauses(GeneralizedAtom atom)
Returns the set of (instantiated) clauses where the head unifies with given bayesian atom.

Parameters:
atom - a bayesian atom.
Returns:
a sets of bayesian clauses.

getClauses

public java.util.Set<Clause> getClauses()
Returns the clauses of this program.

Returns:
the clauses of this program.

isEntailed

public java.lang.String isEntailed(GeneralizedAtom atom)
                            throws CycleFoundException
Checks whether the given atom is entailed by this prolog program.

Parameters:
atom - a bayesian atom.
Returns:
"true" iff the given atom is entailed by this program, "null" otherwise.
Throws:
CycleFoundException

isEntailed

public java.lang.String isEntailed(GeneralizedAtom atom,
                                   java.util.List<AtomExpression> evidences)
                            throws CycleFoundException
Checks whether the given atom is entailed by this prolog program.

Parameters:
atom - a bayesian atom.
evidences - a list of evidences treated as additional facts for the program.
Returns:
"true" iff the given atom is entailed by this program, "null" otherwise.
Throws:
CycleFoundException

closure

public java.util.List<AtomExpression> closure(java.util.List<AtomExpression> data,
                                              LanguageFactory language)
Computes the closure of the given list of atom expression, e.g. for every A(c)=true in data and B(X):-A(X) in this program this method adds B(c)=true to data. If by doing so data becomes inconsistent this method returns "null".

Parameters:
data - a list of atom expressions.
Returns:
a list of atom expressions iff data is consistent, "null" otherwise.

mentions

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

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

toString

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

getLanguage

public LanguageFactory getLanguage()