use of edu.cmu.ml.proppr.prove.DprProver in project ProPPR by TeamCohen.
the class EqualityTest method test.
@Test
public void test() throws LogicProgramException, IOException {
WamProgram program = WamBaseProgram.load(new File(EQUALITY_PROGRAM));
Prover prover = new DprProver();
ProofGraph moral = new StateProofGraph(Query.parse("moral(X)"), new APROptions(), program);
Collection<Query> bobs = prover.solvedQueries(moral, new StatusLogger()).keySet();
// Map<State,Double> ans = prover.prove(moral);
// ArrayList<Query> bobs = new ArrayList<Query>();
// for (Map.Entry<State,Double> e : ans.entrySet()) {
// if (e.getKey().isCompleted()) bobs.add(moral.fill(e.getKey()));
// }
assertEquals(1, bobs.size());
Query bob = bobs.iterator().next();
assertEquals(1, bob.getRhs().length);
assertEquals("Answer should be bob", "bob", bob.getRhs()[0].getArg(0).getName());
}
use of edu.cmu.ml.proppr.prove.DprProver 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.DprProver in project ProPPR by TeamCohen.
the class FactsPluginTest method test.
@Test
public void test() throws LogicProgramException {
APROptions apr = new APROptions();
FactsPlugin p = FactsPlugin.load(apr, new File(GrounderTest.FACTS), false);
WamProgram program = new WamBaseProgram();
Query q = Query.parse("validClass(X)");
StateProofGraph pg = new StateProofGraph(q, apr, program, p);
Prover prover = new DprProver();
Map<String, Double> sols = prover.solutions(pg, new StatusLogger());
assertEquals(2, sols.size());
}
use of edu.cmu.ml.proppr.prove.DprProver 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);
}
Aggregations