Search in sources :

Example 1 with Argument

use of edu.cmu.ml.proppr.prove.wam.Argument in project ProPPR by TeamCohen.

the class Goal method toString.

@Override
public String toString() {
    StringBuilder sb = new StringBuilder(functor);
    if (this.arity > 0) {
        sb.append("(");
        boolean first = true;
        for (Argument a : args) {
            if (!first)
                sb.append(",");
            first = false;
            sb.append(a.getName());
        }
        sb.append(")");
    }
    return sb.toString();
}
Also used : Argument(edu.cmu.ml.proppr.prove.wam.Argument)

Example 2 with Argument

use of edu.cmu.ml.proppr.prove.wam.Argument 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["));
//		}
}
Also used : StatusLogger(edu.cmu.ml.proppr.util.StatusLogger) Query(edu.cmu.ml.proppr.prove.wam.Query) Argument(edu.cmu.ml.proppr.prove.wam.Argument) ConstantArgument(edu.cmu.ml.proppr.prove.wam.ConstantArgument) DfsProver(edu.cmu.ml.proppr.prove.DfsProver) Prover(edu.cmu.ml.proppr.prove.Prover) WamProgram(edu.cmu.ml.proppr.prove.wam.WamProgram) ConstantArgument(edu.cmu.ml.proppr.prove.wam.ConstantArgument) StateProofGraph(edu.cmu.ml.proppr.prove.wam.StateProofGraph) WamPlugin(edu.cmu.ml.proppr.prove.wam.plugins.WamPlugin) Goal(edu.cmu.ml.proppr.prove.wam.Goal) State(edu.cmu.ml.proppr.prove.wam.State) DfsProver(edu.cmu.ml.proppr.prove.DfsProver) APROptions(edu.cmu.ml.proppr.util.APROptions) File(java.io.File) Test(org.junit.Test)

Example 3 with Argument

use of edu.cmu.ml.proppr.prove.wam.Argument 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());
    }
}
Also used : Argument(edu.cmu.ml.proppr.prove.wam.Argument) ConstantArgument(edu.cmu.ml.proppr.prove.wam.ConstantArgument) ConstantArgument(edu.cmu.ml.proppr.prove.wam.ConstantArgument) Test(org.junit.Test)

Example 4 with Argument

use of edu.cmu.ml.proppr.prove.wam.Argument 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());
}
Also used : Outlink(edu.cmu.ml.proppr.prove.wam.Outlink) Query(edu.cmu.ml.proppr.prove.wam.Query) Argument(edu.cmu.ml.proppr.prove.wam.Argument) ConstantArgument(edu.cmu.ml.proppr.prove.wam.ConstantArgument) HashMap(java.util.HashMap) WamProgram(edu.cmu.ml.proppr.prove.wam.WamProgram) ConstantArgument(edu.cmu.ml.proppr.prove.wam.ConstantArgument) StateProofGraph(edu.cmu.ml.proppr.prove.wam.StateProofGraph) Goal(edu.cmu.ml.proppr.prove.wam.Goal) State(edu.cmu.ml.proppr.prove.wam.State) APROptions(edu.cmu.ml.proppr.util.APROptions) File(java.io.File) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Aggregations

Argument (edu.cmu.ml.proppr.prove.wam.Argument)4 ConstantArgument (edu.cmu.ml.proppr.prove.wam.ConstantArgument)3 Test (org.junit.Test)3 Goal (edu.cmu.ml.proppr.prove.wam.Goal)2 Query (edu.cmu.ml.proppr.prove.wam.Query)2 State (edu.cmu.ml.proppr.prove.wam.State)2 StateProofGraph (edu.cmu.ml.proppr.prove.wam.StateProofGraph)2 WamProgram (edu.cmu.ml.proppr.prove.wam.WamProgram)2 APROptions (edu.cmu.ml.proppr.util.APROptions)2 File (java.io.File)2 DfsProver (edu.cmu.ml.proppr.prove.DfsProver)1 Prover (edu.cmu.ml.proppr.prove.Prover)1 Outlink (edu.cmu.ml.proppr.prove.wam.Outlink)1 WamPlugin (edu.cmu.ml.proppr.prove.wam.plugins.WamPlugin)1 StatusLogger (edu.cmu.ml.proppr.util.StatusLogger)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1