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));
}
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);
}
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;
}
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);
}
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);
}
Aggregations