use of edu.cmu.ml.proppr.prove.wam.ConstantArgument in project ProPPR by TeamCohen.
the class SimpleProgramProverTest method testFill.
@Test
public void testFill() 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<State, Double> sols = prover.prove(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 (State s : sols.keySet()) {
if (!s.isCompleted())
continue;
System.out.println(s);
Query a = p.fill(s);
System.out.println(a);
String v = a.getRhs()[0].getArg(1).getName();
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.ConstantArgument 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.prove.wam.ConstantArgument in project ProPPR by TeamCohen.
the class QueryParserTest method testArity1.
@Test
public void testArity1() {
Query q = Query.parse("bob(joe)");
System.out.println(q);
checkTo0(q);
assertEquals("head arity", 1, q.getRhs()[0].getArity());
assertEquals("head arg0", new ConstantArgument("joe"), q.getRhs()[0].getArg(0));
}
use of edu.cmu.ml.proppr.prove.wam.ConstantArgument in project ProPPR by TeamCohen.
the class ArgumentTest method testIsVariableAtom.
@Test
public void testIsVariableAtom() {
Argument a_ = new ConstantArgument("_foo");
assertTrue("Starts with _", a_.isVariableAtom());
String alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
for (int i = 0; i < 26; i++) {
Argument a = new ConstantArgument(alpha.charAt(i) + "foo");
assertTrue("Starts with " + alpha.charAt(i), a.isVariableAtom());
}
}
use of edu.cmu.ml.proppr.prove.wam.ConstantArgument in project ProPPR by TeamCohen.
the class QueryParserTest method testArity2.
@Test
public void testArity2() {
Query q = Query.parse("bob(joe,X)");
q.variabilize();
System.out.println(q);
checkTo0(q);
assertEquals("head arity", 2, q.getRhs()[0].getArity());
assertEquals("head arg0", new ConstantArgument("joe"), q.getRhs()[0].getArg(0));
assertEquals("head arg1", new VariableArgument(-1), q.getRhs()[0].getArg(1));
}
Aggregations