use of edu.cmu.ml.proppr.prove.wam.Outlink in project ProPPR by TeamCohen.
the class WamInterpreterTest method allSolutionsDFS.
public List<State> allSolutionsDFS(WamInterpreter wamInterp, Map<Feature, Double> fd, int depth, List<State> tail) {
if (depth >= MAXDEPTH)
return tail;
if (wamInterp.getState().isCompleted()) {
tail.add(wamInterp.getState());
return tail;
}
for (Outlink o : outlinks(wamInterp)) {
wamInterp.setState(o.child.mutableVersion());
allSolutionsDFS(wamInterp, o.fd, depth + 1, tail);
}
return tail;
}
use of edu.cmu.ml.proppr.prove.wam.Outlink in project ProPPR by TeamCohen.
the class SplitFactsPluginTest method test.
@Test
public void test() throws LogicProgramException {
int input = 0;
int output = 0;
int constants = Configuration.USE_WAM;
int modules = 0;
Configuration c = new Configuration(("--programFiles " + GrounderTest.RULES + ":" + GrounderTest.FACTS + ":" + ADDLFACTS).split(" "), input, output, constants, modules);
assertEquals("# of plugins", c.plugins.length, 1);
assertEquals("# of members", ((SplitFactsPlugin) c.plugins[0]).plugins.size(), 2);
assertTrue("claim", c.plugins[0]._claim("validClass/1"));
Query q = Query.parse("validClass(X)");
WamInterpreter interp = new WamInterpreter(c.program, c.plugins);
int queryStartAddr = c.program.size();
q.variabilize();
c.program.append(q);
interp.executeWithoutBranching(queryStartAddr);
List<Outlink> outs = c.plugins[0].outlinks(interp.saveState(), interp, true);
assertEquals("# outlinks", 6, outs.size());
}
use of edu.cmu.ml.proppr.prove.wam.Outlink in project ProPPR by TeamCohen.
the class InferenceGraphTestTemplate method test.
@Test
public void test() {
InferenceGraph g = getGraph();
MutableState a = new MutableState();
a.setJumpTo("foo");
a.setCanonicalHash(2);
a.setCanonicalForm("a");
MutableState b = new MutableState();
b.setJumpTo("bar");
b.setCanonicalHash(2);
b.setCanonicalForm("b");
MutableState b2 = new MutableState();
b2.setJumpTo("bar");
b2.setCanonicalHash(2);
b2.setCanonicalForm("b");
MutableState c = new MutableState();
c.setJumpTo("baz");
c.setCanonicalHash(3);
c.setCanonicalForm("c");
Map<Feature, Double> fd = new HashMap<Feature, Double>();
fd.put(new Feature("quite"), 1.0);
// a -> b
List<Outlink> outlinks = new ArrayList<Outlink>();
outlinks.add(new Outlink(fd, b));
g.setOutlinks(g.getId(a), outlinks);
// c -> b2 (=b)
outlinks = new ArrayList<Outlink>();
outlinks.add(new Outlink(fd, b2));
g.setOutlinks(g.getId(c), outlinks);
{
String s = g.serialize(true);
String[] parts = s.split("\t");
assertEquals(6, parts.length);
assertEquals("3", parts[0]);
assertEquals("2", parts[1]);
assertEquals("2", parts[2]);
assertEquals("quite", parts[3]);
String[] edges = new String[] { parts[4], parts[5] };
Arrays.sort(edges);
assertEquals("1->2:1@1.0", edges[0]);
assertEquals("3->2:1@1.0", edges[1]);
}
{
String s = g.serialize(false);
String[] parts = s.split("\t");
assertEquals(5, parts.length);
assertEquals("3", parts[0]);
assertEquals("2", parts[1]);
assertEquals("2", parts[2]);
String[] edges = new String[] { parts[3], parts[4] };
Arrays.sort(edges);
assertEquals("1->2:1@1.0", edges[0]);
assertEquals("3->2:1@1.0", edges[1]);
}
}
use of edu.cmu.ml.proppr.prove.wam.Outlink in project ProPPR by TeamCohen.
the class FilterPluginCollection method outlinks.
@Override
public List<Outlink> outlinks(State state, WamInterpreter wamInterp, boolean computeFeatures) throws LogicProgramException {
String jumpTo = state.getJumpTo();
PluginFunction fun = this.registry.get(jumpTo);
wamInterp.restoreState(state);
wamInterp.returnp();
if (!fun.run(wamInterp)) {
wamInterp.getState().setFailed(true);
} else {
wamInterp.executeWithoutBranching();
}
if (computeFeatures) {
return Collections.singletonList(new Outlink(this.fd, wamInterp.saveState()));
}
return Collections.singletonList(new Outlink(Outlink.EMPTY_FD, wamInterp.saveState()));
}
use of edu.cmu.ml.proppr.prove.wam.Outlink in project ProPPR by TeamCohen.
the class SimpleProgramProofGraphTest method normalized.
private Map<State, Double> normalized(List<Outlink> outlinks) {
Map<State, Double> normalized = new HashMap<State, Double>();
double total = 0;
for (Outlink o : outlinks) {
double wt = 0;
for (Map.Entry<Feature, Double> e : o.fd.entrySet()) {
wt += e.getValue();
}
normalized.put(o.child, wt);
total += wt;
}
for (Map.Entry<State, Double> e : normalized.entrySet()) {
e.setValue(e.getValue() / total);
}
return normalized;
}
Aggregations