Search in sources :

Example 6 with InferenceExample

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

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

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

Example 9 with InferenceExample

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

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

Aggregations

InferenceExample (edu.cmu.ml.proppr.examples.InferenceExample)12 Query (edu.cmu.ml.proppr.prove.wam.Query)10 GroundedExample (edu.cmu.ml.proppr.examples.GroundedExample)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 ProofGraph (edu.cmu.ml.proppr.prove.wam.ProofGraph)8 StateProofGraph (edu.cmu.ml.proppr.prove.wam.StateProofGraph)8 APROptions (edu.cmu.ml.proppr.util.APROptions)8 Feature (edu.cmu.ml.proppr.prove.wam.Feature)7 Test (org.junit.Test)7 Grounder (edu.cmu.ml.proppr.Grounder)5 WamPlugin (edu.cmu.ml.proppr.prove.wam.plugins.WamPlugin)4 File (java.io.File)4 State (edu.cmu.ml.proppr.prove.wam.State)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 StatusLogger (edu.cmu.ml.proppr.util.StatusLogger)2 Map (java.util.Map)2