use of edu.cmu.ml.proppr.prove.wam.ProofGraph in project ProPPR by TeamCohen.
the class DuplicateSignatureRuleTest method test2.
@Test
public void test2() throws LogicProgramException, IOException {
APROptions apr = new APROptions("depth=10");
WamProgram program = WamBaseProgram.load(new File(PROGRAM));
ProofGraph pg = new StateProofGraph(Query.parse("canExit(steve,X)"), apr, program);
Prover p = new TracingDfsProver(apr);
Map<Query, Double> result = p.solvedQueries(pg, new StatusLogger());
for (Map.Entry<Query, Double> e : result.entrySet()) {
System.out.println(e.getValue() + "\t" + e.getKey());
assertEquals("Steve not allowed to exit " + e.getKey() + "\n", "canExit(steve,kitchen).", e.getKey().toString());
}
}
use of edu.cmu.ml.proppr.prove.wam.ProofGraph in project ProPPR by TeamCohen.
the class WeightedRulesTest method test.
@Test
public void test() throws IOException, LogicProgramException {
APROptions apr = new APROptions();
Prover p = new DprProver(apr);
WamProgram program = WamBaseProgram.load(RULES);
WamPlugin[] plugins = new WamPlugin[] { FactsPlugin.load(apr, FACTS, false) };
Grounder grounder = new Grounder(apr, p, program, plugins);
assertTrue(plugins[0].claim("ruleWeight#/2"));
Query query = Query.parse("shoppingList(X)");
ProofGraph pg = new StateProofGraph(new InferenceExample(query, new Query[] { Query.parse("shoppingList(kidney_beans)") }, new Query[] { Query.parse("shoppingList(cinnamon)") }), apr, new SimpleSymbolTable<Feature>(), program, plugins);
// Map<String,Double> m = p.solutions(pg);
// System.out.println(Dictionary.buildString(m, new StringBuilder(), "\n").toString());
GroundedExample ex = grounder.groundExample(p, pg);
ex.getGraph().serialize();
String serialized = grounder.serializeGroundedExample(pg, ex).replaceAll("\t", "\n");
System.out.println(serialized);
assertTrue("Rule weights must appear in ground graph (2.0)", serialized.indexOf("2.0") >= 0);
assertTrue("Rule weights must appear in ground graph (3.0)", serialized.indexOf("3.0") >= 0);
}
use of edu.cmu.ml.proppr.prove.wam.ProofGraph in project ProPPR by TeamCohen.
the class SimpleProgramProverTest method test.
@Test
public void test() throws IOException, LogicProgramException {
WamProgram program = WamBaseProgram.load(new File(PROGRAM));
Query q = new Query(new Goal("coworker", new ConstantArgument("steve"), new ConstantArgument("X")));
System.out.println("Query: " + q.toString());
ProofGraph p = new StateProofGraph(q, apr, program);
Prover prover = new DfsProver(apr);
Map<String, Double> sols = prover.solutions(p, new StatusLogger());
assertEquals(2, sols.size());
HashMap<String, Integer> expected = new HashMap<String, Integer>();
expected.put("steve", 0);
expected.put("sven", 0);
System.out.println("Query: " + q.toString());
for (String pair : sols.keySet()) {
System.out.println(pair);
String[] parts = pair.split(":");
String v = parts[1];
System.out.println("Got solution: " + v);
if (expected.containsKey(v))
expected.put(v, expected.get(v) + 1);
}
for (Map.Entry<String, Integer> e : expected.entrySet()) assertEquals(e.getKey(), 1, e.getValue().intValue());
}
use of edu.cmu.ml.proppr.prove.wam.ProofGraph in project ProPPR by TeamCohen.
the class WeightedFeaturesTest method testAsFacts.
@Test
public void testAsFacts() throws IOException, LogicProgramException {
APROptions apr = new APROptions();
Prover p = new DprProver(apr);
WamProgram program = WamBaseProgram.load(RULES);
WamPlugin[] plugins = new WamPlugin[] { FactsPlugin.load(apr, LABELS, false), FactsPlugin.load(apr, WORDSFACTS, false) };
Grounder grounder = new Grounder(apr, p, program, plugins);
assertTrue(plugins[1].claim("hasWord#/3"));
Query query = Query.parse("predict(p1,Y)");
ProofGraph pg = new StateProofGraph(new InferenceExample(query, new Query[] { Query.parse("predict(p1,pos)") }, new Query[] { Query.parse("predict(p1,neg)") }), apr, new SimpleSymbolTable<Feature>(), program, plugins);
GroundedExample ex = grounder.groundExample(p, pg);
String serialized = grounder.serializeGroundedExample(pg, ex).replaceAll("\t", "\n");
System.out.println(serialized);
// hack
assertTrue("Word weights must appear in ground graph", serialized.indexOf("0.9") > 0);
assertTrue("Word weights must appear in ground graph", serialized.indexOf("0.1") > 0);
}
use of edu.cmu.ml.proppr.prove.wam.ProofGraph in project ProPPR by TeamCohen.
the class GrounderTest method noNegativeExamplesTest.
@Test
public void noNegativeExamplesTest() throws IOException, LogicProgramException {
APROptions apr = new APROptions();
WamProgram program = WamBaseProgram.load(new File(RULES));
WamPlugin[] plugins = new WamPlugin[] { FactsPlugin.load(apr, new File(FACTS), false) };
Prover p = new DprProver(apr);
Grounder grounder = new Grounder(apr, p, program, plugins);
InferenceExample ix = new InferenceExample(Query.parse("predict(howard,Y)"), new Query[] { Query.parse("predict(howard,bird)") }, new Query[] {});
GroundedExample ex = grounder.groundExample(p, ix);
makeAssertions(ex, "dpr+", 10, 23, 1.0, 1, "7", 0, "");
ix = new InferenceExample(Query.parse("predict(howard,Y)"), new Query[] { Query.parse("predict(howard,bird)") }, new Query[] {});
ProofGraph pg = p.makeProofGraph(ix, apr, program, plugins);
State pos = null;
Map<State, Double> sols = p.prove(pg, new StatusLogger());
System.out.println(pg.serialize(ex));
}
Aggregations