Search in sources :

Example 26 with Query

use of edu.cmu.ml.proppr.prove.wam.Query in project ProPPR by TeamCohen.

the class FactsPluginTest method test.

@Test
public void test() throws LogicProgramException {
    APROptions apr = new APROptions();
    FactsPlugin p = FactsPlugin.load(apr, new File(GrounderTest.FACTS), false);
    WamProgram program = new WamBaseProgram();
    Query q = Query.parse("validClass(X)");
    StateProofGraph pg = new StateProofGraph(q, apr, program, p);
    Prover prover = new DprProver();
    Map<String, Double> sols = prover.solutions(pg, new StatusLogger());
    assertEquals(2, sols.size());
}
Also used : StatusLogger(edu.cmu.ml.proppr.util.StatusLogger) Query(edu.cmu.ml.proppr.prove.wam.Query) 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) FactsPlugin(edu.cmu.ml.proppr.prove.wam.plugins.FactsPlugin) APROptions(edu.cmu.ml.proppr.util.APROptions) File(java.io.File) WamBaseProgram(edu.cmu.ml.proppr.prove.wam.WamBaseProgram) Test(org.junit.Test) GrounderTest(edu.cmu.ml.proppr.GrounderTest)

Example 27 with Query

use of edu.cmu.ml.proppr.prove.wam.Query in project ProPPR by TeamCohen.

the class SparseGraphPluginTest method testDegree.

@Test
public void testDegree() throws LogicProgramException {
    Query q = Query.parse("child(pam,X)");
    StateProofGraph pg = new StateProofGraph(q, apr, program, plugin);
    // minus 1 for reset
    assertEquals(3, pg.pgDegree(pg.getStartState()) - 1);
}
Also used : Query(edu.cmu.ml.proppr.prove.wam.Query) StateProofGraph(edu.cmu.ml.proppr.prove.wam.StateProofGraph) Test(org.junit.Test)

Example 28 with Query

use of edu.cmu.ml.proppr.prove.wam.Query 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)

Aggregations

Query (edu.cmu.ml.proppr.prove.wam.Query)28 Test (org.junit.Test)21 StateProofGraph (edu.cmu.ml.proppr.prove.wam.StateProofGraph)19 WamProgram (edu.cmu.ml.proppr.prove.wam.WamProgram)18 APROptions (edu.cmu.ml.proppr.util.APROptions)15 Prover (edu.cmu.ml.proppr.prove.Prover)14 ProofGraph (edu.cmu.ml.proppr.prove.wam.ProofGraph)12 File (java.io.File)12 StatusLogger (edu.cmu.ml.proppr.util.StatusLogger)11 InferenceExample (edu.cmu.ml.proppr.examples.InferenceExample)10 DprProver (edu.cmu.ml.proppr.prove.DprProver)10 GroundedExample (edu.cmu.ml.proppr.examples.GroundedExample)8 State (edu.cmu.ml.proppr.prove.wam.State)8 ConstantArgument (edu.cmu.ml.proppr.prove.wam.ConstantArgument)7 Feature (edu.cmu.ml.proppr.prove.wam.Feature)7 Map (java.util.Map)7 Grounder (edu.cmu.ml.proppr.Grounder)5 Goal (edu.cmu.ml.proppr.prove.wam.Goal)5 WamPlugin (edu.cmu.ml.proppr.prove.wam.plugins.WamPlugin)5 HashMap (java.util.HashMap)4