mln
Class MarkovLogicNetwork

java.lang.Object
  extended by mln.MarkovLogicNetwork

public class MarkovLogicNetwork
extends java.lang.Object

An MLN. Holds the symbol table.


Constructor Summary
MarkovLogicNetwork()
          Constructor of MLN.
 
Method Summary
 void 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.
 void closeFiles()
          Close all file handles used by each predicate in listPred.
 void createActTables()
          Create database table related to active atoms.
 void destroyActTables()
          Drop active tables created by createActTables()
 void dumpMapAnswer(java.lang.String fout)
          Dump a MAP world produced by MAP inference.
 void dumpSoftEvidence(java.lang.String fout)
          Write soft evidence to a file.
 void executeAllDatalogRules()
          Execute all Datalog rules
 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 clause object by integer ID.
 Function getFunctionByName(java.lang.String name)
          Get a function by its name; can be built-in.
 int getNumPredicates()
          Returns the total count of predicates in this MLN.
 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.
 Predicate getPredicateByAtomID(int aid)
          Decodes the predicate from an atom id.
 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.
static void initStatic()
           
 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 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 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 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
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MarkovLogicNetwork

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

Method Detail

applyAllScopes

public void applyAllScopes()
Execute all scoping rules


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

closeFiles

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


createActTables

public void createActTables()
Create database table related to active atoms. For each predicate, there is such a table named Predicate.getRelAct(). The schema of this table is like
+-----+ | id | +-----+


destroyActTables

public void destroyActTables()
Drop active tables created by createActTables()


dumpMapAnswer

public void dumpMapAnswer(java.lang.String fout)
Dump a MAP world produced by MAP inference.

Parameters:
fout - path of output file

dumpSoftEvidence

public void dumpSoftEvidence(java.lang.String fout)
Write soft evidence to a file. Ground atoms for each predicate are sorted in descending probabilities.

Parameters:
fout -

executeAllDatalogRules

public void executeAllDatalogRules()
Execute all Datalog rules


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 clause object by integer ID. Accept 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.

getFunctionByName

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

Parameters:
name -

getNumPredicates

public int getNumPredicates()
Returns the total count of predicates in this MLN.


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.


getPredicateByAtomID

public Predicate getPredicateByAtomID(int aid)
Decodes the predicate from an atom id.

Parameters:
aid - the atom id
Returns:
the Predicate object.
See Also:
Predicate.setID(int)

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.


initStatic

public static void initStatic()

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)

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(), RDB.createConstantTable(Hashtable)

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 -

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()

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)