Search in sources :

Example 1 with ConstantArgument

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());
}
Also used : StatusLogger(edu.cmu.ml.proppr.util.StatusLogger) Query(edu.cmu.ml.proppr.prove.wam.Query) StateProofGraph(edu.cmu.ml.proppr.prove.wam.StateProofGraph) ProofGraph(edu.cmu.ml.proppr.prove.wam.ProofGraph) HashMap(java.util.HashMap) 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) Goal(edu.cmu.ml.proppr.prove.wam.Goal) State(edu.cmu.ml.proppr.prove.wam.State) DfsProver(edu.cmu.ml.proppr.prove.DfsProver) File(java.io.File) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 2 with ConstantArgument

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["));
//		}
}
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 ConstantArgument

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

Example 4 with ConstantArgument

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());
    }
}
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 5 with ConstantArgument

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

Aggregations

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