use of edu.cmu.ml.proppr.prove.wam.Feature in project ProPPR by TeamCohen.
the class WamInterpreterTest method outlinks.
public List<Outlink> outlinks(WamInterpreter wamInterp) {
List<Outlink> result = new ArrayList<Outlink>();
if (!wamInterp.getState().isCompleted() && !wamInterp.getState().isFailed()) {
assertTrue("not at a call", wamInterp.getState().getJumpTo() != null);
assertTrue("no definition for " + wamInterp.getState().getJumpTo(), wamInterp.getProgram().hasLabel(wamInterp.getState().getJumpTo()));
State savedState = wamInterp.saveState();
for (Integer addr : wamInterp.getProgram().getAddresses(wamInterp.getState().getJumpTo())) {
wamInterp.restoreState(savedState);
//try and match the rule head
Map<Feature, Double> features = wamInterp.executeWithoutBranching(addr);
if (!features.isEmpty() && !wamInterp.getState().isFailed()) {
wamInterp.executeWithoutBranching();
if (!wamInterp.getState().isFailed()) {
result.add(new Outlink(features, wamInterp.getState()));
}
}
}
}
return result;
}
use of edu.cmu.ml.proppr.prove.wam.Feature in project ProPPR by TeamCohen.
the class WamInterpreterTest method findAnswers.
public List<State> findAnswers(WamInterpreter wamInterp, Query query) {
WamProgram program = wamInterp.getProgram();
int queryStartAddr = program.size();
query.variabilize();
program.append(query);
Map<Feature, Double> features = wamInterp.executeWithoutBranching(queryStartAddr);
assertEquals(0, features.size());
List<State> result = allSolutionsDFS(wamInterp, makeFeatures(new Feature("root")));
program.revert();
return result;
}
use of edu.cmu.ml.proppr.prove.wam.Feature in project ProPPR by TeamCohen.
the class WeightedEdgeTest method testOne.
public void testOne(APROptions apr, WamPlugin plug) throws IOException, LogicProgramException {
Prover p = new DprProver(apr);
WamProgram program = WamBaseProgram.load(RULES);
WamPlugin[] plugins = new WamPlugin[] { plug };
Grounder grounder = new Grounder(apr, p, program, plugins);
assertTrue("Missing weighted functor", plugins[0].claim("hasWord#/3"));
Query query = Query.parse("words(p1,W)");
ProofGraph pg = new StateProofGraph(new InferenceExample(query, new Query[] { Query.parse("words(p1,good)") }, new Query[] { Query.parse("words(p1,thing)") }), 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);
String serialized = ex.getGraph().serialize(true).replaceAll("\t", "\n");
//String serialized = grounder.serializeGroundedExample(pg, ex).replaceAll("\t", "\n");
System.out.println(serialized);
assertTrue("Label weights must appear in ground graph (0.9)", serialized.indexOf("0.9") >= 0);
assertTrue("Label weights must appear in ground graph (0.1)", serialized.indexOf("0.1") >= 0);
// Map<String,Double> m = p.solvedQueries(pg);
// System.out.println(Dictionary.buildString(m, new StringBuilder(), "\n"));
Query query2 = Query.parse("words2(p1,W)");
ProofGraph pg2 = new StateProofGraph(new InferenceExample(query2, new Query[] { Query.parse("words(p1,good)") }, new Query[] { Query.parse("words(p1,thing)") }), apr, new SimpleSymbolTable<Feature>(), program, plugins);
// Map<String,Double> m = p.solutions(pg);
// System.out.println(Dictionary.buildString(m, new StringBuilder(), "\n").toString());
GroundedExample ex2 = grounder.groundExample(p, pg2);
String serialized2 = ex2.getGraph().serialize(true).replaceAll("\t", "\n");
//String serialized = grounder.serializeGroundedExample(pg, ex).replaceAll("\t", "\n");
System.out.println(serialized2);
assertTrue("Label weights must appear in ground graph (0.9)", serialized2.indexOf("0.9") >= 0);
assertTrue("Label weights must appear in ground graph (0.1)", serialized2.indexOf("0.1") >= 0);
}
use of edu.cmu.ml.proppr.prove.wam.Feature in project ProPPR by TeamCohen.
the class WeightedFeaturesTest method testAsGraph.
@Test
public void testAsGraph() 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), LightweightGraphPlugin.load(apr, WORDSGRAPH, -1) };
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);
}
use of edu.cmu.ml.proppr.prove.wam.Feature in project ProPPR by TeamCohen.
the class BoundVariableGraphTest method test.
@Test
public void test() throws IOException, LogicProgramException {
APROptions apr = new APROptions();
Prover p = new DprProver(apr);
// Prover p = new TracingDfsProver(apr);
WamProgram program = WamBaseProgram.load(RULES);
WamPlugin[] plugins = new WamPlugin[] { LightweightGraphPlugin.load(apr, GRAPH) };
Grounder grounder = new Grounder(apr, p, program, plugins);
Query query = Query.parse("hasWord(p1,good)");
ProofGraph pg = new StateProofGraph(new InferenceExample(query, new Query[] { Query.parse("hasWord(p1,good)") }, new Query[0]), 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);
assertEquals("Too many edges", 4, ex.getGraph().edgeSize());
// Map<String,Double> m = p.solvedQueries(pg);
// System.out.println(Dictionary.buildString(m, new StringBuilder(), "\n"));
}
Aggregations