Search in sources :

Example 1 with GroundedExample

use of edu.cmu.ml.proppr.examples.GroundedExample 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);
}
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) Grounder(edu.cmu.ml.proppr.Grounder)

Example 2 with GroundedExample

use of edu.cmu.ml.proppr.examples.GroundedExample 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);
}
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)

Example 3 with GroundedExample

use of edu.cmu.ml.proppr.examples.GroundedExample 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"));
}
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) TracingDfsProver(edu.cmu.ml.proppr.prove.TracingDfsProver) 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)

Example 4 with GroundedExample

use of edu.cmu.ml.proppr.examples.GroundedExample in project ProPPR by TeamCohen.

the class NodeMergingTest method doTest.

private void doTest(File rules, File facts, String squery, String[] spos, String[] sneg, int nodeSize, int posSize) throws LogicProgramException, IOException {
    APROptions apr = new APROptions();
    Prover p = new DprProver(apr);
    WamProgram program = WamBaseProgram.load(rules);
    WamPlugin[] plugins = null;
    if (facts.getName().endsWith(FactsPlugin.FILE_EXTENSION))
        plugins = new WamPlugin[] { FactsPlugin.load(apr, facts, false) };
    else if (facts.getName().endsWith(GraphlikePlugin.FILE_EXTENSION))
        plugins = new WamPlugin[] { LightweightGraphPlugin.load(apr, facts, -1) };
    Grounder grounder = new Grounder(apr, p, program, plugins);
    Query query = Query.parse(squery);
    Query[] pos = new Query[spos.length];
    for (int i = 0; i < spos.length; i++) pos[i] = Query.parse(spos[i]);
    Query[] neg = new Query[sneg.length];
    for (int i = 0; i < sneg.length; i++) neg[i] = Query.parse(sneg[i]);
    ProofGraph pg = new StateProofGraph(new InferenceExample(query, pos, neg), apr, new SimpleSymbolTable<Feature>(), program, plugins);
    GroundedExample ex = grounder.groundExample(pg);
    System.out.println(grounder.serializeGroundedExample(pg, ex).replaceAll("\t", "\n"));
    if (nodeSize >= 0)
        assertEquals("improper node duplication", nodeSize, ex.getGraph().nodeSize());
    if (posSize >= 0)
        assertEquals("improper # solutions found", posSize, ex.getPosList().size());
}
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) WamPlugin(edu.cmu.ml.proppr.prove.wam.plugins.WamPlugin) APROptions(edu.cmu.ml.proppr.util.APROptions)

Example 5 with GroundedExample

use of edu.cmu.ml.proppr.examples.GroundedExample in project ProPPR by TeamCohen.

the class GrounderTest method doGroundExampleTest.

public void doGroundExampleTest(String msg, Prover p, int nodes, int edges, double value, String npos, String nneg, double alpha) 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) };
    Grounder grounder = new Grounder(apr, p, program, plugins);
    Query query = Query.parse("predict(howard,Y)");
    GroundedExample ex = grounder.groundExample(p, new InferenceExample(query, new Query[] { Query.parse("predict(howard,bird)") }, new Query[] { Query.parse("predict(howard,mammal)") }));
    makeAssertions(ex, msg, nodes, edges, value, 1, npos, 1, nneg);
// predict(howard,Y)	+predict(howard,bird)	-predict(howard,mammal)
}
Also used : WamPlugin(edu.cmu.ml.proppr.prove.wam.plugins.WamPlugin) GroundedExample(edu.cmu.ml.proppr.examples.GroundedExample) Query(edu.cmu.ml.proppr.prove.wam.Query) WamProgram(edu.cmu.ml.proppr.prove.wam.WamProgram) APROptions(edu.cmu.ml.proppr.util.APROptions) File(java.io.File) InferenceExample(edu.cmu.ml.proppr.examples.InferenceExample)

Aggregations

GroundedExample (edu.cmu.ml.proppr.examples.GroundedExample)10 InferenceExample (edu.cmu.ml.proppr.examples.InferenceExample)9 WamProgram (edu.cmu.ml.proppr.prove.wam.WamProgram)9 DprProver (edu.cmu.ml.proppr.prove.DprProver)8 Prover (edu.cmu.ml.proppr.prove.Prover)8 Query (edu.cmu.ml.proppr.prove.wam.Query)8 APROptions (edu.cmu.ml.proppr.util.APROptions)8 ProofGraph (edu.cmu.ml.proppr.prove.wam.ProofGraph)7 StateProofGraph (edu.cmu.ml.proppr.prove.wam.StateProofGraph)7 Feature (edu.cmu.ml.proppr.prove.wam.Feature)6 Test (org.junit.Test)6 Grounder (edu.cmu.ml.proppr.Grounder)5 WamPlugin (edu.cmu.ml.proppr.prove.wam.plugins.WamPlugin)4 File (java.io.File)3 IdDprProver (edu.cmu.ml.proppr.prove.IdDprProver)2 IdPprProver (edu.cmu.ml.proppr.prove.IdPprProver)2 PprProver (edu.cmu.ml.proppr.prove.PprProver)2 State (edu.cmu.ml.proppr.prove.wam.State)2 TracingDfsProver (edu.cmu.ml.proppr.prove.TracingDfsProver)1 StatusLogger (edu.cmu.ml.proppr.util.StatusLogger)1