use of edu.cmu.ml.proppr.prove.wam.ConstantArgument in project ProPPR by TeamCohen.
the class SimpleProgramProofGraphTest method test.
@Test
public void test() throws LogicProgramException, IOException {
WamProgram program = WamBaseProgram.load(new File(SimpleProgramProverTest.PROGRAM));
Query q = new Query(new Goal("coworker", new ConstantArgument("steve"), new ConstantArgument("X")));
StateProofGraph pg = new StateProofGraph(q, new APROptions(), program);
HashMap<String, Integer> solutions = new HashMap<String, Integer>();
solutions.put("steve", 0);
solutions.put("sven", 0);
Map<State, Double> vec = new HashMap<State, Double>();
vec.put(pg.getStartState(), 1.0);
// step 1: coworker -> employee,boss
System.out.println("Step 1");
for (State s : vec.keySet()) System.out.println(s);
List<Outlink> outlinks = pg.pgOutlinks(pg.getStartState(), false);
assertEquals("1. coworker :- employee,boss", 2, outlinks.size());
vec = nextVec(vec, normalized(outlinks));
vec.remove(pg.getStartState());
assertEquals("1. statecount", 1, vec.size());
// step 2:
System.out.println("Step 2");
for (State s : vec.keySet()) System.out.println(s);
outlinks = pg.pgOutlinks(vec.keySet().iterator().next(), false);
assertEquals("2. employee :- management,boss", 2, outlinks.size());
vec = nextVec(vec, normalized(outlinks));
vec.remove(pg.getStartState());
assertEquals("2. statecount", 1, vec.size());
// step 3:
System.out.println("Step 3");
for (State s : vec.keySet()) System.out.println(s);
outlinks = pg.pgOutlinks(vec.keySet().iterator().next(), false);
assertEquals("3. management :- sookie", 2, outlinks.size());
vec = nextVec(vec, normalized(outlinks));
vec.remove(pg.getStartState());
assertEquals("3. statecount", 1, vec.size());
// step 4:
System.out.println("Step 4");
for (State s : vec.keySet()) System.out.println(s);
outlinks = pg.pgOutlinks(vec.keySet().iterator().next(), false);
assertEquals("4. boss(sookie,X) :- _steve_ + sven", 2, outlinks.size());
vec = nextVec(vec, normalized(outlinks));
vec.remove(pg.getStartState());
assertEquals("4. statecount", 1, vec.size());
// step 5:
System.out.println("Step 5");
for (State s : vec.keySet()) {
System.out.println(s);
System.out.println(Dictionary.buildString(pg.asDict(s), new StringBuilder(), "\n\t").substring(1));
}
outlinks = pg.pgOutlinks(vec.keySet().iterator().next(), false);
assertEquals("5. boss(sookie,X) :- steve + sven", 3, outlinks.size());
vec = nextVec(vec, normalized(outlinks));
vec.remove(pg.getStartState());
assertEquals("5. statecount", 2, vec.size());
// step 6:
System.out.println("Step 6");
for (State s : vec.keySet()) {
System.out.println(s);
Map<Argument, String> dict = pg.asDict(s);
System.out.println(Dictionary.buildString(dict, new StringBuilder(), "\n\t").substring(1));
assertTrue(s.isCompleted());
for (String v : dict.values()) {
if (solutions.containsKey(v))
solutions.put(v, solutions.get(v) + 1);
}
}
for (Map.Entry<String, Integer> e : solutions.entrySet()) assertEquals(e.getKey(), 1, e.getValue().intValue());
}
use of edu.cmu.ml.proppr.prove.wam.ConstantArgument 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.ConstantArgument in project ProPPR by TeamCohen.
the class WamInterpreterTest method test.
@Test
public void test() throws IOException {
WamProgram program = WamBaseProgram.load(new File(SimpleProgramProverTest.PROGRAM));
WamInterpreter interp = new WamInterpreter(program, new WamPlugin[0]);
// ? :- coworker(steve,X).
Query query = new Query(new Goal("coworker", new ConstantArgument("steve"), new ConstantArgument("X")));
List<State> answers = findAnswers(interp, query);
for (State s : answers) System.out.println(s);
assertEquals(2, answers.size());
}
Aggregations