use of edu.cmu.ml.proppr.prove.FeatureDictWeighter in project ProPPR by TeamCohen.
the class ProverTestTemplate method testProveState.
@Test
public void testProveState() throws LogicProgramException {
log.info("testProveState");
FeatureDictWeighter w = new InnerProductWeighter();
SymbolTable<Feature> featureTab = new SimpleSymbolTable<Feature>();
int milk = featureTab.getId(new Feature("milk"));
w.put(featureTab.getSymbol(milk), 2);
prover.setWeighter(w);
ProofGraph pg = prover.makeProofGraph(new InferenceExample(Query.parse("isa(elsie,X)"), null, null), apr, featureTab, lpMilk, fMilk);
//("isa","elsie","X"));
Map<State, Double> dist = prover.prove(pg, new StatusLogger());
double query = 0.0;
double platypus = 0.0;
double others = 0.0;
double all = 0.0;
for (Map.Entry<State, Double> s : dist.entrySet()) {
Query q = pg.fill(s.getKey());
String arg2 = q.getRhs()[0].getArg(1).getName();
if ("platypus".equals(arg2)) {
platypus = Math.max(platypus, s.getValue());
} else if ("X1".equals(arg2)) {
query = Math.max(query, s.getValue());
} else {
others = Math.max(others, s.getValue());
}
System.out.println(q + "\t" + s.getValue());
all += s.getValue();
}
System.out.println();
System.out.println("query weight: " + query);
System.out.println("platypus weight: " + platypus);
System.out.println("others weight: " + others);
// assertTrue("query should retain most weight",query > Math.max(platypus,others));
assertTrue("milk-featured paths should score higher than others", platypus > others);
assertEquals("Total weight of all states should be around 1.0", 1.0, all, 10 * this.apr.epsilon);
assertEquals("Known features", 1, prover.weighter.numKnownFeatures);
assertEquals("Unknown features", 5, prover.weighter.numUnknownFeatures);
}
Aggregations