Search in sources :

Example 11 with APROptions

use of edu.cmu.ml.proppr.util.APROptions in project ProPPR by TeamCohen.

the class WeightedEdgeTest method testFacts.

@Test
public void testFacts() throws IOException, LogicProgramException {
    APROptions apr = new APROptions();
    testOne(apr, FactsPlugin.load(apr, FACTS, false));
}
Also used : APROptions(edu.cmu.ml.proppr.util.APROptions) Test(org.junit.Test)

Example 12 with APROptions

use of edu.cmu.ml.proppr.util.APROptions in project ProPPR by TeamCohen.

the class WeightedEdgeTest method testGraph.

@Test
public void testGraph() throws IOException, LogicProgramException {
    APROptions apr = new APROptions();
    testOne(apr, LightweightGraphPlugin.load(apr, GRAPH, 1000));
}
Also used : APROptions(edu.cmu.ml.proppr.util.APROptions) Test(org.junit.Test)

Example 13 with APROptions

use of edu.cmu.ml.proppr.util.APROptions 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)

Example 14 with APROptions

use of edu.cmu.ml.proppr.util.APROptions 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)

Example 15 with APROptions

use of edu.cmu.ml.proppr.util.APROptions in project ProPPR by TeamCohen.

the class GrounderTest method doGroundExampleTest.

public void doGroundExampleTest(String msg, Prover p, int nodes, int edges, double value, String npos, String nneg, double alpha) throws IOException, LogicProgramException {
    APROptions apr = new APROptions();
    WamProgram program = WamBaseProgram.load(new File(RULES));
    WamPlugin[] plugins = new WamPlugin[] { FactsPlugin.load(apr, new File(FACTS), false) };
    Grounder grounder = new Grounder(apr, p, program, plugins);
    Query query = Query.parse("predict(howard,Y)");
    GroundedExample ex = grounder.groundExample(p, new InferenceExample(query, new Query[] { Query.parse("predict(howard,bird)") }, new Query[] { Query.parse("predict(howard,mammal)") }));
    makeAssertions(ex, msg, nodes, edges, value, 1, npos, 1, nneg);
// predict(howard,Y)	+predict(howard,bird)	-predict(howard,mammal)
}
Also used : WamPlugin(edu.cmu.ml.proppr.prove.wam.plugins.WamPlugin) GroundedExample(edu.cmu.ml.proppr.examples.GroundedExample) Query(edu.cmu.ml.proppr.prove.wam.Query) WamProgram(edu.cmu.ml.proppr.prove.wam.WamProgram) APROptions(edu.cmu.ml.proppr.util.APROptions) File(java.io.File) InferenceExample(edu.cmu.ml.proppr.examples.InferenceExample)

Aggregations

APROptions (edu.cmu.ml.proppr.util.APROptions)19 WamProgram (edu.cmu.ml.proppr.prove.wam.WamProgram)15 Test (org.junit.Test)15 Query (edu.cmu.ml.proppr.prove.wam.Query)14 StateProofGraph (edu.cmu.ml.proppr.prove.wam.StateProofGraph)13 Prover (edu.cmu.ml.proppr.prove.Prover)12 DprProver (edu.cmu.ml.proppr.prove.DprProver)11 File (java.io.File)10 GroundedExample (edu.cmu.ml.proppr.examples.GroundedExample)8 InferenceExample (edu.cmu.ml.proppr.examples.InferenceExample)8 ProofGraph (edu.cmu.ml.proppr.prove.wam.ProofGraph)8 StatusLogger (edu.cmu.ml.proppr.util.StatusLogger)7 WamPlugin (edu.cmu.ml.proppr.prove.wam.plugins.WamPlugin)6 Feature (edu.cmu.ml.proppr.prove.wam.Feature)5 Grounder (edu.cmu.ml.proppr.Grounder)4 State (edu.cmu.ml.proppr.prove.wam.State)3 GrounderTest (edu.cmu.ml.proppr.GrounderTest)2 IdDprProver (edu.cmu.ml.proppr.prove.IdDprProver)2 IdPprProver (edu.cmu.ml.proppr.prove.IdPprProver)2 PprProver (edu.cmu.ml.proppr.prove.PprProver)2