tuffy.mln
Class MarkovLogicNetwork

java.lang.Object
  extended by tuffy.mln.MarkovLogicNetwork
All Implemented Interfaces:
java.lang.Cloneable

public class MarkovLogicNetwork
extends java.lang.Object
implements java.lang.Cloneable

An MLN. Holds the symbol table.


Field Summary
 java.util.HashSet<ConjunctiveQuery> dedupalogRules
           
 java.lang.String relAtomPart
           
 java.lang.String relAtoms
           
 java.lang.String relClausePart
           
 java.lang.String relClauses
          Database tables storing intermediate data.
 java.lang.String relTrueAtoms
           
 java.util.ArrayList<Clause> unnormalizedClauses
          List of unnormalized clauses.
 
Constructor Summary
MarkovLogicNetwork()
          Constructor of MLN.
 
Method Summary
 boolean applyAllScopes()
          Execute all scoping rules
 boolean cleanUp()
          Clean up temporary data in DB and working dir, including 1) drop schema in PostgreSQL; 2) remove directory.
 java.lang.Object clone()
           
 void closeFiles()
          Close all file handles used by each predicate in listPred.
 void executeAllDatalogRules()
          Execute all Datalog rules
 void executeAllIntermediateRules()
           
 void executeAllPostprocRules()
          Execute all Postprocessing rules
 void finalizeClauseDefinitions(RDB adb)
          Finalize the definitions of all clauses, i.e., prepare the database table used by each clause, including 1) instance table for each clause; 2) SQL needed to ground this clause.
 java.util.ArrayList<ConjunctiveQuery> getAllDatalogRules()
           
 java.util.ArrayList<Clause> getAllNormalizedClauses()
          Return all normalized clauses.
 java.util.HashSet<Predicate> getAllPred()
          Return the set of all predicates.
 java.util.ArrayList<Predicate> getAllPredOrderByName()
           
 java.util.ArrayList<Clause> getAllUnnormalizedClauses()
          Return all unnormalized clauses as read from the input file.
 Clause getClauseById(int id)
          Get the clause object by integer ID.
 RDB getDB()
           
 Function getFunctionByName(java.lang.String name)
          Get a function by its name; can be built-in.
 int getID()
           
 Type getOrCreateTypeByName(java.lang.String name)
          Return the type of a given name; create if this type does not exist.
 Predicate getPredByName(java.lang.String name)
          Return the predicate of the given name; null if such predicate does not exist.
 RDB getRDB()
          Returns the RDB used by this MLN.
 java.util.HashSet<Clause> getRelevantClauses()
          Returns the set of relevant clauses.
 int getSymbolID(java.lang.String symbol, Type type)
          Return assigned ID of a constant symbol.
 boolean isScoped(Predicate p)
          Test whether a predicate is scoped
 void loadEvidences(java.lang.String[] evidFiles)
          Parse multiple MLN evidence files.
 void loadPrograms(java.lang.String[] progFiles)
          Parse multiple MLN program files.
 void loadProgramsButNotNormalizeClauses(java.lang.String[] progFiles)
           
 void loadQueries(java.lang.String[] queryFiles)
          Parse multiple MLN query files.
 void materializeTables()
          Stores constants and evidence into database table.
 void normalizeClauses()
          Normalize all clauses.
 void parseQueryCommaList(java.lang.String queryAtoms)
          Read in the query atoms provided by the command line.
 void prepareDB(RDB adb)
          Prepare the database for each predicate and clause.
 void registerClause(Clause c)
          Registers a new, unnormalized clause.
 void registerDatalogRule(ConjunctiveQuery cq)
          Add a datalog rule
 void registerIntermediateRule(ConjunctiveQuery cq)
           
 void registerPostprocRule(ConjunctiveQuery cq)
           
 void registerPred(Predicate p)
          Register a new predicate.
 void registerScopingRule(ConjunctiveQuery cq)
          Add a scoping rule
 void setClauseAsRelevant(Clause c)
          Marks a clause as relevant.
 void setDB(RDB adb)
           
 void storeAllEvidence()
          Store all evidences into the database by flushing the "buffers".
 void storeAllQueries()
          Ground and store all query atoms.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

dedupalogRules

public java.util.HashSet<ConjunctiveQuery> dedupalogRules

relAtomPart

public java.lang.String relAtomPart

relAtoms

public java.lang.String relAtoms

relClausePart

public java.lang.String relClausePart

relClauses

public java.lang.String relClauses
Database tables storing intermediate data.


relTrueAtoms

public java.lang.String relTrueAtoms

unnormalizedClauses

public java.util.ArrayList<Clause> unnormalizedClauses
List of unnormalized clauses.

Constructor Detail

MarkovLogicNetwork

public MarkovLogicNetwork()
Constructor of MLN. parser will be constructed here.

Method Detail

applyAllScopes

public boolean applyAllScopes()
Execute all scoping rules

Returns:
true iff there is at least one scoping rule

cleanUp

public boolean cleanUp()
Clean up temporary data in DB and working dir, including 1) drop schema in PostgreSQL; 2) remove directory.

Returns:
true on success

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Overrides:
clone in class java.lang.Object
Throws:
java.lang.CloneNotSupportedException

closeFiles

public void closeFiles()
Close all file handles used by each predicate in listPred.


executeAllDatalogRules

public void executeAllDatalogRules()
Execute all Datalog rules


executeAllIntermediateRules

public void executeAllIntermediateRules()

executeAllPostprocRules

public void executeAllPostprocRules()
Execute all Postprocessing rules


finalizeClauseDefinitions

public void finalizeClauseDefinitions(RDB adb)
Finalize the definitions of all clauses, i.e., prepare the database table used by each clause, including 1) instance table for each clause; 2) SQL needed to ground this clause. Call this when all clauses have been parsed.


getAllDatalogRules

public java.util.ArrayList<ConjunctiveQuery> getAllDatalogRules()

getAllNormalizedClauses

public java.util.ArrayList<Clause> getAllNormalizedClauses()
Return all normalized clauses.


getAllPred

public java.util.HashSet<Predicate> getAllPred()
Return the set of all predicates.


getAllPredOrderByName

public java.util.ArrayList<Predicate> getAllPredOrderByName()

getAllUnnormalizedClauses

public java.util.ArrayList<Clause> getAllUnnormalizedClauses()
Return all unnormalized clauses as read from the input file.


getClauseById

public Clause getClauseById(int id)
Get the clause object by integer ID. Accepts negative id, and will translate it into positive. Does not accept zero id or id larger than the number of clauses, and will return null.

Parameters:
id - ID of wanted clause.

getDB

public RDB getDB()

getFunctionByName

public Function getFunctionByName(java.lang.String name)
Get a function by its name; can be built-in.

Parameters:
name -

getID

public int getID()

getOrCreateTypeByName

public Type getOrCreateTypeByName(java.lang.String name)
Return the type of a given name; create if this type does not exist.


getPredByName

public Predicate getPredByName(java.lang.String name)
Return the predicate of the given name; null if such predicate does not exist.


getRDB

public RDB getRDB()
Returns the RDB used by this MLN.


getRelevantClauses

public java.util.HashSet<Clause> getRelevantClauses()
Returns the set of relevant clauses.


getSymbolID

public int getSymbolID(java.lang.String symbol,
                       Type type)
Return assigned ID of a constant symbol. If this symbol is a new one, a new ID will be assigned to it, and the symbol table will be updated.


isScoped

public boolean isScoped(Predicate p)
Test whether a predicate is scoped


loadEvidences

public void loadEvidences(java.lang.String[] evidFiles)
Parse multiple MLN evidence files. If file size is larger than 1MB, then uses a file stream incrementally parse this file. Can also accept .gz file (see GZIPInputStream.GZIPInputStream(InputStream)).

Parameters:
evidFiles - list of MLN evidence files (in Alchemy format)

loadPrograms

public void loadPrograms(java.lang.String[] progFiles)
Parse multiple MLN program files.

Parameters:
progFiles - list of MLN program files (in Alchemy format)

loadProgramsButNotNormalizeClauses

public void loadProgramsButNotNormalizeClauses(java.lang.String[] progFiles)

loadQueries

public void loadQueries(java.lang.String[] queryFiles)
Parse multiple MLN query files.

Parameters:
queryFiles - list of MLN query files (in Alchemy format)

materializeTables

public void materializeTables()
Stores constants and evidence into database table.

See Also:
materializeAllTypes(RDB), storeAllEvidence()

normalizeClauses

public void normalizeClauses()
Normalize all clauses. If the signature of this clause is as the same as some some existing clauses in listClauses, then Clause.absorb(Clause) this new clause. If not absorbed, this new clause is set an ID sequentially and a name Clause$id. Predicates in this clause is registered by Predicate.addRelatedClause(Clause).

See Also:
Clause.normalize(), Clause.absorb(Clause)

parseQueryCommaList

public void parseQueryCommaList(java.lang.String queryAtoms)
Read in the query atoms provided by the command line.


prepareDB

public void prepareDB(RDB adb)
Prepare the database for each predicate and clause.

See Also:
Predicate.prepareDB(RDB), finalizeClauseDefinitions(RDB)

registerClause

public void registerClause(Clause c)
Registers a new, unnormalized clause.

Parameters:
c - the clause to be registered

registerDatalogRule

public void registerDatalogRule(ConjunctiveQuery cq)
Add a datalog rule

Parameters:
cq -

registerIntermediateRule

public void registerIntermediateRule(ConjunctiveQuery cq)

registerPostprocRule

public void registerPostprocRule(ConjunctiveQuery cq)

registerPred

public void registerPred(Predicate p)
Register a new predicate. Here by ``register'' it means 1) set ID for this predicate sequentially; 2) push it into listPred; 3) building the map from predicate name to this predicate.


registerScopingRule

public void registerScopingRule(ConjunctiveQuery cq)
Add a scoping rule

Parameters:
cq -

setClauseAsRelevant

public void setClauseAsRelevant(Clause c)
Marks a clause as relevant. Called by KBMC.

See Also:
KBMC.run()

setDB

public void setDB(RDB adb)

storeAllEvidence

public void storeAllEvidence()
Store all evidences into the database by flushing the "buffers". These tuples are pushed into the relational table Predicate.getRelName() in the database.


storeAllQueries

public void storeAllQueries()
Ground and store all query atoms.

See Also:
Predicate.addQuery(Atom), Predicate.groundAndStoreAtom(Atom)