Search in sources :

Example 11 with ProofGraph

use of edu.cmu.ml.proppr.prove.wam.ProofGraph 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());
}
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) DfsProver(edu.cmu.ml.proppr.prove.DfsProver) File(java.io.File) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 12 with ProofGraph

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

the class WeightedFeaturesTest method testAsFacts.

@Test
public void testAsFacts() 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), FactsPlugin.load(apr, WORDSFACTS, false) };
    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);
}
Also used : GroundedExample(edu.cmu.ml.proppr.examples.GroundedExample) Query(edu.cmu.ml.proppr.prove.wam.Query) StateProofGraph(edu.cmu.ml.proppr.prove.wam.StateProofGraph) ProofGraph(edu.cmu.ml.proppr.prove.wam.ProofGraph) DprProver(edu.cmu.ml.proppr.prove.DprProver) Prover(edu.cmu.ml.proppr.prove.Prover) DprProver(edu.cmu.ml.proppr.prove.DprProver) WamProgram(edu.cmu.ml.proppr.prove.wam.WamProgram) StateProofGraph(edu.cmu.ml.proppr.prove.wam.StateProofGraph) Feature(edu.cmu.ml.proppr.prove.wam.Feature) InferenceExample(edu.cmu.ml.proppr.examples.InferenceExample) APROptions(edu.cmu.ml.proppr.util.APROptions) Grounder(edu.cmu.ml.proppr.Grounder) Test(org.junit.Test)

Aggregations

ProofGraph (edu.cmu.ml.proppr.prove.wam.ProofGraph)12 Query (edu.cmu.ml.proppr.prove.wam.Query)12 StateProofGraph (edu.cmu.ml.proppr.prove.wam.StateProofGraph)12 Prover (edu.cmu.ml.proppr.prove.Prover)11 WamProgram (edu.cmu.ml.proppr.prove.wam.WamProgram)11 Test (org.junit.Test)10 InferenceExample (edu.cmu.ml.proppr.examples.InferenceExample)8 DprProver (edu.cmu.ml.proppr.prove.DprProver)8 APROptions (edu.cmu.ml.proppr.util.APROptions)8 GroundedExample (edu.cmu.ml.proppr.examples.GroundedExample)7 Feature (edu.cmu.ml.proppr.prove.wam.Feature)7 StatusLogger (edu.cmu.ml.proppr.util.StatusLogger)6 Grounder (edu.cmu.ml.proppr.Grounder)5 File (java.io.File)5 Map (java.util.Map)4 State (edu.cmu.ml.proppr.prove.wam.State)3 DfsProver (edu.cmu.ml.proppr.prove.DfsProver)2 TracingDfsProver (edu.cmu.ml.proppr.prove.TracingDfsProver)2 ConstantArgument (edu.cmu.ml.proppr.prove.wam.ConstantArgument)2 Goal (edu.cmu.ml.proppr.prove.wam.Goal)2