tuffy.mln
Class Predicate

java.lang.Object
  extended by tuffy.mln.Predicate

public class Predicate
extends java.lang.Object

Predicate in First Order Logic.


Field Summary
 boolean isCurrentlyView
           
 
Constructor Summary
Predicate(MarkovLogicNetwork mln, java.lang.String aname, boolean aClosedWorld)
          Constructor of Predicate.
 
Method Summary
 void addDependentAttrPosition(int i)
          Set the attribute at position i to be dependent.
 void addEvidence(Atom a)
          Store an evidence in the "buffer".
 void addFunctionalDependency(java.util.List<java.lang.String> determinant, java.lang.String dependent)
          Add a functional dependency for the attributes of this predicate
 void addQuery(Atom q)
          Register a query atom.
 void addRelatedClause(Clause c)
          Register a clause referencing this predicate
 void appendArgument(Type t)
          Append a new argument without a user-provided name.
 void appendArgument(Type t, java.lang.String name)
          Append a new argument with a user provided name.
 int arity()
          Return the arity of this predicate.
 void closeFiles()
          Close all file handles.
 void flushEvidence()
          Flush the evidence buffer to the predicate table, using the COPY statement in PostgreSQL.
 int getArgPositionByName(java.lang.String aname)
          Return the position of the given argument name.
 java.util.ArrayList<java.lang.String> getArgs()
          Return argument names of this predicate.
static Predicate getBuiltInPredByName(java.lang.String s)
          Return the predicate object with the name as the argument string.
 java.util.ArrayList<java.lang.Integer> getDependentAttrPositions()
           
 java.util.ArrayList<java.lang.String> getDependentAttrs()
          Get attributes whose value depend on other attributes in any possible world.
 int getID()
          Return the assigned ID of this predicate in its parent MLN.
 java.util.ArrayList<java.lang.Integer> getKeyAttrPositions()
           
 java.util.ArrayList<java.lang.String> getKeyAttrs()
          Get attributes that form a possible world key.
 java.lang.String getName()
          Return the name of this predicate.
 java.util.ArrayList<Atom> getQueryAtoms()
          Return query atoms of this predicate.
 java.lang.String getRelAct()
          Return the name of relational table containing the ID of active atoms associated with this predicate.
 java.util.HashSet<Clause> getRelatedClauses()
          Return clauses referencing this predicate.
 java.lang.String getRelName()
          Return the relational table name of this predicate..
 Type getTypeAt(int k)
          Return the type of the k-th argument.
 void groundAndStoreAtom(Atom a)
          Ground an atom and store the result in the database.
 boolean hasDependentAttributes()
           
 boolean hasMoreToGround()
          Determine whether this predicate can ground more atoms.
 boolean hasQuery()
          Checks if there are any queries associated with this predicate.
 boolean hasSoftEvidence()
           
 boolean isBuiltIn()
           
static boolean isBuiltInPredName(java.lang.String s)
          Return true if the argument is the name of a built-in predicate.
 boolean isClosedWorld()
          Check if this predicate makes the closed-world assumption.
 boolean isCompletelySepcified()
           
 boolean isImmutable()
           
 boolean isSafeRefOnly()
           
 boolean noNeedToGround()
          Check if we need to ground this predicate on top of its evidence.
 void prepareDB(RDB adb)
          Initialize database objects for this predicate.
 void sealDefinition()
          Mark the point when all arguments have been given.
 void setAllQuery()
          Specify that all atoms of this predicate are queries.
 void setClosedWorld(boolean t)
          Specify whether this predicate obeys the closed world assumption.
 void setCompeletelySpecified(boolean t)
           
 void setDB(RDB adb)
           
 void setHasSoftEvidence(boolean hasSoftEvidence)
           
 void setID(int aid)
          Assign an ID for this predicate.
 void setMLN(MarkovLogicNetwork _mln)
           
 void setSafeRefOnly(boolean safeRefOnly)
          Set whether all references to this predicate are safe; i.e., all variables in corresponding positive literals are bound to other literals in the same clause.
 void storeQueries()
          Ground query atoms and store the result in the database.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

isCurrentlyView

public boolean isCurrentlyView
Constructor Detail

Predicate

public Predicate(MarkovLogicNetwork mln,
                 java.lang.String aname,
                 boolean aClosedWorld)
Constructor of Predicate.

Parameters:
mln - the parent MLN that hosts this predicate
aname - the name; must be unique
aClosedWorld - indicates whether to make the closed-world asssumption
Method Detail

addDependentAttrPosition

public void addDependentAttrPosition(int i)
Set the attribute at position i to be dependent. Non-dependent attributes form a possible-world key.

Parameters:
i -

addEvidence

public void addEvidence(Atom a)
Store an evidence in the "buffer". There is a buffer (in the form of a CSV file) for each predicate that holds the DB tuple formats of its evidence; this buffer will be flushed into the database once all evidence has been read.

Parameters:
a - the evidence; following Alchemy, it must be a ground atom
See Also:
flushEvidence()

addFunctionalDependency

public void addFunctionalDependency(java.util.List<java.lang.String> determinant,
                                    java.lang.String dependent)
Add a functional dependency for the attributes of this predicate

Parameters:
determinant -
dependent -

addQuery

public void addQuery(Atom q)
Register a query atom.

Parameters:
q - the query atom; could contain variables
See Also:
storeQueries()

addRelatedClause

public void addRelatedClause(Clause c)
Register a clause referencing this predicate

Parameters:
c - a clause referencing this predicate

appendArgument

public void appendArgument(Type t)
Append a new argument without a user-provided name.

Parameters:
t - the type of the new argument

appendArgument

public void appendArgument(Type t,
                           java.lang.String name)
Append a new argument with a user provided name.

Parameters:
t - the type of the new argument
name - user-provided name for this argument/attribute

arity

public int arity()
Return the arity of this predicate.


closeFiles

public void closeFiles()
Close all file handles.


flushEvidence

public void flushEvidence()
Flush the evidence buffer to the predicate table, using the COPY statement in PostgreSQL.

See Also:
addEvidence(Atom)

getArgPositionByName

public int getArgPositionByName(java.lang.String aname)
Return the position of the given argument name.

Parameters:
aname - argument name

getArgs

public java.util.ArrayList<java.lang.String> getArgs()
Return argument names of this predicate. The K-th argument is named "TypeK", where "Type" if the type name of this argument.


getBuiltInPredByName

public static Predicate getBuiltInPredByName(java.lang.String s)
Return the predicate object with the name as the argument string.

Parameters:
s - name of queried predicate
Returns:
the predicate object with name s.

getDependentAttrPositions

public java.util.ArrayList<java.lang.Integer> getDependentAttrPositions()

getDependentAttrs

public java.util.ArrayList<java.lang.String> getDependentAttrs()
Get attributes whose value depend on other attributes in any possible world.

See Also:
getKeyAttrs()

getID

public int getID()
Return the assigned ID of this predicate in its parent MLN.


getKeyAttrPositions

public java.util.ArrayList<java.lang.Integer> getKeyAttrPositions()

getKeyAttrs

public java.util.ArrayList<java.lang.String> getKeyAttrs()
Get attributes that form a possible world key.

See Also:
getDependentAttrs()

getName

public java.lang.String getName()
Return the name of this predicate.


getQueryAtoms

public java.util.ArrayList<Atom> getQueryAtoms()
Return query atoms of this predicate. Used by KBMC.


getRelAct

public java.lang.String getRelAct()
Return the name of relational table containing the ID of active atoms associated with this predicate.


getRelatedClauses

public java.util.HashSet<Clause> getRelatedClauses()
Return clauses referencing this predicate.


getRelName

public java.lang.String getRelName()
Return the relational table name of this predicate..


getTypeAt

public Type getTypeAt(int k)
Return the type of the k-th argument.


groundAndStoreAtom

public void groundAndStoreAtom(Atom a)
Ground an atom and store the result in the database. Repetitive invocations of this method could be expensive, since it involves both updates and inserts to the predicate table. First, for the grounded tuples satisfying this atom $a$ and already existing in database, it only update its club values. If this $a$ is query, then add query to club (0->1, 2->3). If this $a$ is evidence, then add evidence to club (0->2, 1->3). Then, for the grounded tuples satisfying this atom $a$ and not existing in database, it 1) select them with a $arity-way join in corresponding type instance table; 2) left join them with current version database; 3) select those not matching with any existing tuples; and 4) insert into the database.


hasDependentAttributes

public boolean hasDependentAttributes()

hasMoreToGround

public boolean hasMoreToGround()
Determine whether this predicate can ground more atoms. This predicate does not have more to ground if the number of unknown grounds (none and query) in this predicate is smaller than the number of active atoms of this predicate. I.e., all the unknown atoms of this predicate is activated.

Returns:
whether there are more groundings can be generated

hasQuery

public boolean hasQuery()
Checks if there are any queries associated with this predicate.


hasSoftEvidence

public boolean hasSoftEvidence()

isBuiltIn

public boolean isBuiltIn()

isBuiltInPredName

public static boolean isBuiltInPredName(java.lang.String s)
Return true if the argument is the name of a built-in predicate.

Parameters:
s - name of queried predicate
Returns:
true if s is a built-in predicate.

isClosedWorld

public boolean isClosedWorld()
Check if this predicate makes the closed-world assumption.


isCompletelySepcified

public boolean isCompletelySepcified()

isImmutable

public boolean isImmutable()

isSafeRefOnly

public boolean isSafeRefOnly()

noNeedToGround

public boolean noNeedToGround()
Check if we need to ground this predicate on top of its evidence. A predicate needs not to ground if 1) it only appears in negative literal and 2) it follows closed world assumption.

Returns:
true if the closed world assumption is made on this predicate, and all literals of this predicate are negative

prepareDB

public void prepareDB(RDB adb)
Initialize database objects for this predicate.


sealDefinition

public void sealDefinition()
Mark the point when all arguments have been given. Go through the arguments again to try to give unnamed arguments names.


setAllQuery

public void setAllQuery()
Specify that all atoms of this predicate are queries.


setClosedWorld

public void setClosedWorld(boolean t)
Specify whether this predicate obeys the closed world assumption.


setCompeletelySpecified

public void setCompeletelySpecified(boolean t)

setDB

public void setDB(RDB adb)

setHasSoftEvidence

public void setHasSoftEvidence(boolean hasSoftEvidence)

setID

public void setID(int aid)
Assign an ID for this predicate. This predicate ID is used to encode tuple IDs of this predicate.


setMLN

public void setMLN(MarkovLogicNetwork _mln)

setSafeRefOnly

public void setSafeRefOnly(boolean safeRefOnly)
Set whether all references to this predicate are safe; i.e., all variables in corresponding positive literals are bound to other literals in the same clause.

Parameters:
safeRefOnly -

storeQueries

public void storeQueries()
Ground query atoms and store the result in the database.