00001 package edu.tum.cs.srl.bayesnets.bln.py; 00002 00003 import java.util.Properties; 00004 00005 import org.python.core.PyObject.ConversionException; 00006 import org.python.util.PythonInterpreter; 00007 00008 import edu.tum.cs.srl.Database; 00009 import edu.tum.cs.srl.bayesnets.RelationalBeliefNetwork; 00010 import edu.tum.cs.srl.bayesnets.bln.AbstractBayesianLogicNetwork; 00011 import edu.tum.cs.srl.bayesnets.bln.AbstractGroundBLN; 00012 import edu.tum.cs.tools.JythonInterpreter; 00013 00019 public class BayesianLogicNetworkPy extends AbstractBayesianLogicNetwork { 00020 public RelationalBeliefNetwork rbn; 00021 public String logicFile; 00022 public JythonInterpreter jython; 00023 protected State state; 00024 00025 public BayesianLogicNetworkPy(RelationalBeliefNetwork rbn, String logicFile) { 00026 super(rbn, logicFile); 00027 state = null; 00028 00029 // initialize jython interpreter 00030 System.out.println("initializing interpreter..."); 00031 Properties props = new Properties(); 00032 props.put("python.path", ".:/usr/wiss/jain/work/code/SRLDB/bin:/usr/wiss/jain/work/code/SRLDB/datagen:/usr/wiss/jain/work/code/SRLDB/mln"); 00033 PythonInterpreter.initialize(System.getProperties(), props, null); 00034 jython = new JythonInterpreter(); 00035 00036 // load MLN 00037 System.out.println("importing libraries..."); 00038 jython.exec("from MLN import MLN"); 00039 System.out.println("loading logic network..."); 00040 jython.exec("mln = MLN('%s')", logicFile); 00041 } 00042 00043 public void generateGroundFormulas(String domainFile) { 00044 jython.exec("mln.combineDB('%s')", domainFile); 00045 state = new State(jython); 00046 } 00047 00048 public State getState() { 00049 return state; 00050 } 00051 00052 public GroundFormulaIteration iterGroundFormulas() throws ConversionException { 00053 return new GroundFormulaIteration(this); 00054 } 00055 00056 @Override 00057 public GroundBLN ground(Database db) throws Exception { 00058 return new GroundBLN(this, db); 00059 } 00060 }