00001 package edu.tum.cs.srl;
00002
00003 import java.util.Collection;
00004 import java.util.Set;
00005 import java.util.Vector;
00006
00007 import edu.tum.cs.srl.bayesnets.RelationalBeliefNetwork;
00008 import edu.tum.cs.srl.bayesnets.RelationalNode;
00009
00015 public class ParameterGrounder {
00023 @Deprecated
00024 public static Collection<String[]> generateGroundings(RelationalNode node, Database db) throws Exception {
00025 return generateGroundings(db, node.getSignature().argTypes);
00026 }
00027
00035 public static Collection<String[]> generateGroundings(Signature sig, Database db) throws Exception {
00036 return generateGroundings(db, sig.argTypes);
00037 }
00038
00047 public static Collection<String[]> generateGroundings(RelationalModel model, String function, Database db) throws Exception {
00048 try {
00049 return generateGroundings(db, model.getSignature(function).argTypes);
00050 }
00051 catch(Exception e) {
00052 System.err.println("Warning: " + e.getMessage() + " (while grounding '" + function + "')");
00053 return new Vector<String[]>();
00054 }
00055 }
00056
00057 public static Collection<String[]> generateGroundings(Database db, String[] domainNames) throws Exception {
00058 Vector<String[]> ret = new Vector<String[]>();
00059 generateGroundings(ret, db, new String[domainNames.length], domainNames, 0);
00060 return ret;
00061 }
00062
00063
00064 private static void generateGroundings(Collection<String[]> ret, Database db, String[] params, String[] domainNames, int i) throws Exception {
00065
00066 if(i == domainNames.length) {
00067 ret.add(params.clone());
00068 return;
00069 }
00070
00071 Iterable<String> domain = db.getDomain(domainNames[i]);
00072 if(domain == null)
00073 throw new Exception("Domain " + domainNames[i] + " not found in the database!");
00074 for(String element : domain) {
00075 params[i] = element;
00076 generateGroundings(ret, db, params, domainNames, i+1);
00077 }
00078 }
00079 }