use of edu.cmu.ml.proppr.util.APROptions in project ProPPR by TeamCohen.
the class UngroundedSolutionsTest method test.
@Test
public void test() throws IOException, LogicProgramException {
WamProgram program = WamBaseProgram.load(new File(PROGRAM));
APROptions apr = new APROptions("depth=20");
WamPlugin facts = LightweightGraphPlugin.load(apr, new File(FACTS));
Query q = new Query(new Goal("grandparent", new ConstantArgument("X"), new ConstantArgument("Y")));
// q.variabilize();
StateProofGraph pg = new StateProofGraph(q, apr, program, facts);
Prover p = new DfsProver(apr);
Map<State, Double> ans = p.prove(pg, new StatusLogger());
// Map<LogicProgramState,Double> ans = p.proveState(program, new ProPPRLogicProgramState(Goal.decompile("grandparent,-1,-2")));
System.out.println("===");
for (State s : ans.keySet()) {
if (s.isCompleted()) {
System.out.println(s);
Map<Argument, String> dict = pg.asDict(s);
System.out.println(Dictionary.buildString(dict, new StringBuilder(), "\n\t").substring(1));
for (String a : dict.values()) {
// a = a.substring(a.indexOf(":"));
assertFalse(a.startsWith("X"));
}
}
}
// System.out.println("===");
// for (String s : Prover.filterSolutions(ans).keySet()) {
// System.out.println(s);
// assertFalse("Filtered solutions contain variables",s.contains("v["));
// }
}
use of edu.cmu.ml.proppr.util.APROptions in project ProPPR by TeamCohen.
the class WeightedFeaturesTest method testAsGraph.
@Test
public void testAsGraph() 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), LightweightGraphPlugin.load(apr, WORDSGRAPH, -1) };
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.util.APROptions in project ProPPR by TeamCohen.
the class BoundVariableGraphTest method test.
@Test
public void test() throws IOException, LogicProgramException {
APROptions apr = new APROptions();
Prover p = new DprProver(apr);
// Prover p = new TracingDfsProver(apr);
WamProgram program = WamBaseProgram.load(RULES);
WamPlugin[] plugins = new WamPlugin[] { LightweightGraphPlugin.load(apr, GRAPH) };
Grounder grounder = new Grounder(apr, p, program, plugins);
Query query = Query.parse("hasWord(p1,good)");
ProofGraph pg = new StateProofGraph(new InferenceExample(query, new Query[] { Query.parse("hasWord(p1,good)") }, new Query[0]), 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);
assertEquals("Too many edges", 4, ex.getGraph().edgeSize());
// Map<String,Double> m = p.solvedQueries(pg);
// System.out.println(Dictionary.buildString(m, new StringBuilder(), "\n"));
}
use of edu.cmu.ml.proppr.util.APROptions 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.util.APROptions 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());
}
Aggregations