use of edu.cmu.ml.proppr.prove.wam.StateProofGraph in project ProPPR by TeamCohen.
the class TestNeqPlugin method test.
@Test
public void test() throws IOException, LogicProgramException {
APROptions apr = new APROptions();
WamProgram program = WamProgram.load(new File(PROGRAM));
Query different = Query.parse("different(door,cat)");
Query same = Query.parse("different(lake,lake)");
Prover p = new DprProver(apr);
StatusLogger s = new StatusLogger();
assertEquals("different should have 1 solution", 1, p.solutions(new StateProofGraph(different, apr, program), s).size());
assertEquals("same should have no solution", 0, p.solutions(new StateProofGraph(same, apr, program), s).size());
}
use of edu.cmu.ml.proppr.prove.wam.StateProofGraph in project ProPPR by TeamCohen.
the class NodeMergingTest method doTest.
private void doTest(File rules, File facts, String squery, String[] spos, String[] sneg, int nodeSize, int posSize) throws LogicProgramException, IOException {
APROptions apr = new APROptions();
Prover p = new DprProver(apr);
WamProgram program = WamBaseProgram.load(rules);
WamPlugin[] plugins = null;
if (facts.getName().endsWith(FactsPlugin.FILE_EXTENSION))
plugins = new WamPlugin[] { FactsPlugin.load(apr, facts, false) };
else if (facts.getName().endsWith(GraphlikePlugin.FILE_EXTENSION))
plugins = new WamPlugin[] { LightweightGraphPlugin.load(apr, facts, -1) };
Grounder grounder = new Grounder(apr, p, program, plugins);
Query query = Query.parse(squery);
Query[] pos = new Query[spos.length];
for (int i = 0; i < spos.length; i++) pos[i] = Query.parse(spos[i]);
Query[] neg = new Query[sneg.length];
for (int i = 0; i < sneg.length; i++) neg[i] = Query.parse(sneg[i]);
ProofGraph pg = new StateProofGraph(new InferenceExample(query, pos, neg), apr, new SimpleSymbolTable<Feature>(), program, plugins);
GroundedExample ex = grounder.groundExample(pg);
System.out.println(grounder.serializeGroundedExample(pg, ex).replaceAll("\t", "\n"));
if (nodeSize >= 0)
assertEquals("improper node duplication", nodeSize, ex.getGraph().nodeSize());
if (posSize >= 0)
assertEquals("improper # solutions found", posSize, ex.getPosList().size());
}
use of edu.cmu.ml.proppr.prove.wam.StateProofGraph 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.StateProofGraph in project ProPPR by TeamCohen.
the class PathDprProverTest method test.
@Test
public void test() throws IOException, LogicProgramException {
APROptions apr = new APROptions();
apr.epsilon = 1e-5;
apr.alpha = 0.01;
WamProgram program = WamBaseProgram.load(new File(RULES));
WamPlugin[] plugins = new WamPlugin[] { SparseGraphPlugin.load(apr, new File(SparseGraphPluginTest.PLUGIN)) };
PathDprProver p = new PathDprProver(apr);
Query query = Query.parse("kids(bette,Y)");
StateProofGraph pg = new StateProofGraph(query, apr, program, plugins);
p.prove(pg, new StatusLogger());
}
use of edu.cmu.ml.proppr.prove.wam.StateProofGraph 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);
}
Aggregations