Search in sources :

Example 6 with GroundedExample

use of edu.cmu.ml.proppr.examples.GroundedExample in project ProPPR by TeamCohen.

the class GrounderTest method noNegativeExamplesTest.

@Test
public void noNegativeExamplesTest() 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) };
    Prover p = new DprProver(apr);
    Grounder grounder = new Grounder(apr, p, program, plugins);
    InferenceExample ix = new InferenceExample(Query.parse("predict(howard,Y)"), new Query[] { Query.parse("predict(howard,bird)") }, new Query[] {});
    GroundedExample ex = grounder.groundExample(p, ix);
    makeAssertions(ex, "dpr+", 10, 23, 1.0, 1, "7", 0, "");
    ix = new InferenceExample(Query.parse("predict(howard,Y)"), new Query[] { Query.parse("predict(howard,bird)") }, new Query[] {});
    ProofGraph pg = p.makeProofGraph(ix, apr, program, plugins);
    State pos = null;
    Map<State, Double> sols = p.prove(pg, new StatusLogger());
    System.out.println(pg.serialize(ex));
}
Also used : StatusLogger(edu.cmu.ml.proppr.util.StatusLogger) 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) IdDprProver(edu.cmu.ml.proppr.prove.IdDprProver) PprProver(edu.cmu.ml.proppr.prove.PprProver) DprProver(edu.cmu.ml.proppr.prove.DprProver) IdPprProver(edu.cmu.ml.proppr.prove.IdPprProver) Prover(edu.cmu.ml.proppr.prove.Prover) IdDprProver(edu.cmu.ml.proppr.prove.IdDprProver) DprProver(edu.cmu.ml.proppr.prove.DprProver) WamProgram(edu.cmu.ml.proppr.prove.wam.WamProgram) InferenceExample(edu.cmu.ml.proppr.examples.InferenceExample) WamPlugin(edu.cmu.ml.proppr.prove.wam.plugins.WamPlugin) State(edu.cmu.ml.proppr.prove.wam.State) APROptions(edu.cmu.ml.proppr.util.APROptions) File(java.io.File) Test(org.junit.Test)

Example 7 with GroundedExample

use of edu.cmu.ml.proppr.examples.GroundedExample in project ProPPR by TeamCohen.

the class GrounderTest method unboundLabelsTest.

@Test(expected = IllegalArgumentException.class)
public void unboundLabelsTest() 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) };
    Prover p = new DprProver(apr);
    Grounder grounder = new Grounder(apr, p, program, plugins);
    InferenceExample ix = new InferenceExample(Query.parse("predict(howard,Bird)"), new Query[] { Query.parse("predict(howard,Bird)") }, new Query[] {});
    GroundedExample ex = grounder.groundExample(p, ix);
}
Also used : WamPlugin(edu.cmu.ml.proppr.prove.wam.plugins.WamPlugin) GroundedExample(edu.cmu.ml.proppr.examples.GroundedExample) IdDprProver(edu.cmu.ml.proppr.prove.IdDprProver) PprProver(edu.cmu.ml.proppr.prove.PprProver) DprProver(edu.cmu.ml.proppr.prove.DprProver) IdPprProver(edu.cmu.ml.proppr.prove.IdPprProver) Prover(edu.cmu.ml.proppr.prove.Prover) IdDprProver(edu.cmu.ml.proppr.prove.IdDprProver) DprProver(edu.cmu.ml.proppr.prove.DprProver) 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) Test(org.junit.Test)

Example 8 with GroundedExample

use of edu.cmu.ml.proppr.examples.GroundedExample in project ProPPR by TeamCohen.

the class Grounder method groundExample.

/**
	 * Run the prover to produce a proof of an example
	 * @param rawX
	 * @return
	 * @throws LogicProgramException 
	 */
public GroundedExample groundExample(Prover<P> p, P pg) throws LogicProgramException {
    if (log.isTraceEnabled())
        log.trace("thawed example: " + pg.getExample().toString());
    Map<State, Double> ans = p.prove(pg, status);
    GroundedExample ground = pg.makeRWExample(ans);
    if (this.graphKeyFile != null) {
        saveGraphKey(ground, pg);
    }
    return ground;
}
Also used : GroundedExample(edu.cmu.ml.proppr.examples.GroundedExample) State(edu.cmu.ml.proppr.prove.wam.State)

Example 9 with GroundedExample

use of edu.cmu.ml.proppr.examples.GroundedExample in project ProPPR by TeamCohen.

the class WeightedRulesTest method test.

@Test
public void test() throws IOException, LogicProgramException {
    APROptions apr = new APROptions();
    Prover p = new DprProver(apr);
    WamProgram program = WamBaseProgram.load(RULES);
    WamPlugin[] plugins = new WamPlugin[] { FactsPlugin.load(apr, FACTS, false) };
    Grounder grounder = new Grounder(apr, p, program, plugins);
    assertTrue(plugins[0].claim("ruleWeight#/2"));
    Query query = Query.parse("shoppingList(X)");
    ProofGraph pg = new StateProofGraph(new InferenceExample(query, new Query[] { Query.parse("shoppingList(kidney_beans)") }, new Query[] { Query.parse("shoppingList(cinnamon)") }), apr, new SimpleSymbolTable<Feature>(), program, plugins);
    //		Map<String,Double> m = p.solutions(pg);
    //		System.out.println(Dictionary.buildString(m, new StringBuilder(), "\n").toString());
    GroundedExample ex = grounder.groundExample(p, pg);
    ex.getGraph().serialize();
    String serialized = grounder.serializeGroundedExample(pg, ex).replaceAll("\t", "\n");
    System.out.println(serialized);
    assertTrue("Rule weights must appear in ground graph (2.0)", serialized.indexOf("2.0") >= 0);
    assertTrue("Rule weights must appear in ground graph (3.0)", serialized.indexOf("3.0") >= 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 10 with GroundedExample

use of edu.cmu.ml.proppr.examples.GroundedExample 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

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