edu.cs.ai.kreator.models
Class Query

java.lang.Object
  extended by edu.cs.ai.kreator.models.Query

public class Query
extends java.lang.Object

This class models a general query for a knowledgebase of the form Q1=q1,...,QN=qN | E1=e1,...,EM=eM with the informal interpretation of "what is the probability of Q1=q1 and ... and QN=qN if I know E1=e1 and ... and EM=eM".

Author:
Matthias Thimm, Sebastian Loh.

Field Summary
protected  java.util.List<AtomExpression> evidences
          The evidence expressions of this query
protected  LanguageFactory languageFact
          The language of this query (this should be the same language as the language of the knowledgebase this query addresses).
static org.apache.log4j.Logger LOG
           
protected  java.util.List<AtomExpression> questions
          The query atom expressions atoms of this query.
 
Constructor Summary
Query(java.lang.String queryString, LanguageFactory languageFact, java.util.Collection<AtomExpression> questions)
           
Query(java.lang.String queryString, LanguageFactory languageFact, java.util.Collection<AtomExpression> questions, java.util.Collection<AtomExpression> evidences)
          Constructs a new query.
 
Method Summary
 boolean addEvidence(AtomExpression e)
          Adds the given atom expression to this query as evidence.
 void addEvidences(java.util.List<AtomExpression> e)
          Adds the given atom expressions to this query as evidence.
 java.util.Set<Constant> getConstants()
          returns the set of constants appearing in this query.
 java.util.List<AtomExpression> getEvidences()
           
 java.lang.String getEvidenceValue(GeneralizedAtom atom)
          Determines whether the given generalized atom is used in an evidence atom expression and if so returns the value.
 LanguageFactory getLanguageFact()
           
 java.lang.String getPristineQueryString()
          Returns the unaltered query string that was passed at construction time.
 java.util.List<AtomExpression> getQuestionAtomExpressions()
           
 java.util.List<GeneralizedAtom> getQuestionAtoms()
          Returns a list of the atoms appearing in the "query"-part of this query.
 java.util.List<java.lang.String> getQuestionValues()
          Returns a list of the values appearing in the "query"-part of this query.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

LOG

public static final org.apache.log4j.Logger LOG

languageFact

protected LanguageFactory languageFact
The language of this query (this should be the same language as the language of the knowledgebase this query addresses).


questions

protected java.util.List<AtomExpression> questions
The query atom expressions atoms of this query.


evidences

protected java.util.List<AtomExpression> evidences
The evidence expressions of this query

Constructor Detail

Query

public Query(java.lang.String queryString,
             LanguageFactory languageFact,
             java.util.Collection<AtomExpression> questions,
             java.util.Collection<AtomExpression> evidences)
Constructs a new query.

Parameters:
queryString -
languageFact -
questions -
evidences -
varFactory -

Query

public Query(java.lang.String queryString,
             LanguageFactory languageFact,
             java.util.Collection<AtomExpression> questions)
Method Detail

getEvidenceValue

public java.lang.String getEvidenceValue(GeneralizedAtom atom)
Determines whether the given generalized atom is used in an evidence atom expression and if so returns the value.

Parameters:
atom - a generalized atom.
Returns:
the value of the atom expression with the given atom or "null" if there is no evidence for the given atom.

getQuestionAtoms

public java.util.List<GeneralizedAtom> getQuestionAtoms()
Returns a list of the atoms appearing in the "query"-part of this query.

Returns:
a list of the atoms appearing in the "query"-part of this query.

getQuestionValues

public java.util.List<java.lang.String> getQuestionValues()
Returns a list of the values appearing in the "query"-part of this query. Can be used as a key of a CPD.

Returns:
a list of the values appearing in the "query"-part of this query.

addEvidence

public boolean addEvidence(AtomExpression e)
Adds the given atom expression to this query as evidence.

Parameters:
e - a atom expression
Returns:
"true" if the given atom expression could be added successfully, i.e., if the atom expression wasn't already in this query.

addEvidences

public void addEvidences(java.util.List<AtomExpression> e)
Adds the given atom expressions to this query as evidence.

Parameters:
e - a list of atom expressions

getConstants

public java.util.Set<Constant> getConstants()
returns the set of constants appearing in this query.

Returns:
the set of constants appearing in this query.

getLanguageFact

public LanguageFactory getLanguageFact()

getEvidences

public java.util.List<AtomExpression> getEvidences()

getQuestionAtomExpressions

public java.util.List<AtomExpression> getQuestionAtomExpressions()

toString

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

getPristineQueryString

public java.lang.String getPristineQueryString()
Returns the unaltered query string that was passed at construction time.