00001 package edu.tum.cs.logic; 00002 00003 import edu.tum.cs.srl.Database; 00004 import edu.tum.cs.srl.Signature; 00005 import edu.tum.cs.srl.bayesnets.RelationalBeliefNetwork; 00006 00007 public class PossibleWorldFromDatabase implements IPossibleWorld { 00008 00009 Database db; 00010 RelationalBeliefNetwork rbn; 00011 boolean closedWorld; 00012 00013 public PossibleWorldFromDatabase(RelationalBeliefNetwork rbn, Database db, boolean closedWorld) { 00014 this.db = db; 00015 this.rbn = rbn; 00016 this.closedWorld = closedWorld; 00017 } 00018 00019 public boolean isTrue(GroundAtom ga) { 00020 try { 00021 Signature sig = rbn.getSignature(ga.predicate); 00022 if(sig.isBoolean()) { 00023 String value = db.getVariableValue(ga.toString(), closedWorld); 00024 if(value == null) 00025 throw new RuntimeException("Value of " + ga + " not in the database that is used as a possible world; perhaps it must always be given because it is used in a precondition/decision node."); 00026 boolean tv = value.equalsIgnoreCase("True"); 00027 //System.out.println("value of atom " + ga + " corresponding to boolean function is " + (tv ? "true" : "false")); 00028 return tv; 00029 } 00030 else { 00031 String varName = rbn.gndAtom2VarName(ga); 00032 String value = db.getVariableValue(varName, closedWorld); 00033 if(value == null) 00034 throw new RuntimeException("Value of " + varName + " not in the database that is used as a possible world; perhaps it must always be given because it is used in a precondition/decision node."); 00035 boolean tv = value.equals(ga.args[ga.args.length-1]); 00036 //System.out.println("value of atom " + ga + " corresponding to non-boolean function is " + (tv ? "true" : "false")); 00037 return tv; 00038 } 00039 } 00040 catch(Exception e) { 00041 throw new RuntimeException(e.toString()); 00042 } 00043 } 00044 }