Search in sources :

Example 1 with WamPlugin

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

the class UngroundedSolutionsTest method test.

@Test
public void test() throws IOException, LogicProgramException {
    WamProgram program = WamBaseProgram.load(new File(PROGRAM));
    APROptions apr = new APROptions("depth=20");
    WamPlugin facts = LightweightGraphPlugin.load(apr, new File(FACTS));
    Query q = new Query(new Goal("grandparent", new ConstantArgument("X"), new ConstantArgument("Y")));
    //		q.variabilize();
    StateProofGraph pg = new StateProofGraph(q, apr, program, facts);
    Prover p = new DfsProver(apr);
    Map<State, Double> ans = p.prove(pg, new StatusLogger());
    //		Map<LogicProgramState,Double> ans = p.proveState(program, new ProPPRLogicProgramState(Goal.decompile("grandparent,-1,-2")));
    System.out.println("===");
    for (State s : ans.keySet()) {
        if (s.isCompleted()) {
            System.out.println(s);
            Map<Argument, String> dict = pg.asDict(s);
            System.out.println(Dictionary.buildString(dict, new StringBuilder(), "\n\t").substring(1));
            for (String a : dict.values()) {
                //					a = a.substring(a.indexOf(":"));
                assertFalse(a.startsWith("X"));
            }
        }
    }
//		System.out.println("===");
//		for (String s : Prover.filterSolutions(ans).keySet()) {
//			System.out.println(s);
//			assertFalse("Filtered solutions contain variables",s.contains("v["));
//		}
}
Also used : StatusLogger(edu.cmu.ml.proppr.util.StatusLogger) Query(edu.cmu.ml.proppr.prove.wam.Query) Argument(edu.cmu.ml.proppr.prove.wam.Argument) ConstantArgument(edu.cmu.ml.proppr.prove.wam.ConstantArgument) DfsProver(edu.cmu.ml.proppr.prove.DfsProver) Prover(edu.cmu.ml.proppr.prove.Prover) WamProgram(edu.cmu.ml.proppr.prove.wam.WamProgram) ConstantArgument(edu.cmu.ml.proppr.prove.wam.ConstantArgument) StateProofGraph(edu.cmu.ml.proppr.prove.wam.StateProofGraph) WamPlugin(edu.cmu.ml.proppr.prove.wam.plugins.WamPlugin) Goal(edu.cmu.ml.proppr.prove.wam.Goal) State(edu.cmu.ml.proppr.prove.wam.State) DfsProver(edu.cmu.ml.proppr.prove.DfsProver) APROptions(edu.cmu.ml.proppr.util.APROptions) File(java.io.File) Test(org.junit.Test)

Example 2 with WamPlugin

use of edu.cmu.ml.proppr.prove.wam.plugins.WamPlugin 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 3 with WamPlugin

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

the class PathDprProverTest method test.

@Test
public void test() throws IOException, LogicProgramException {
    APROptions apr = new APROptions();
    apr.epsilon = 1e-5;
    apr.alpha = 0.01;
    WamProgram program = WamBaseProgram.load(new File(RULES));
    WamPlugin[] plugins = new WamPlugin[] { SparseGraphPlugin.load(apr, new File(SparseGraphPluginTest.PLUGIN)) };
    PathDprProver p = new PathDprProver(apr);
    Query query = Query.parse("kids(bette,Y)");
    StateProofGraph pg = new StateProofGraph(query, apr, program, plugins);
    p.prove(pg, new StatusLogger());
}
Also used : StatusLogger(edu.cmu.ml.proppr.util.StatusLogger) WamPlugin(edu.cmu.ml.proppr.prove.wam.plugins.WamPlugin) Query(edu.cmu.ml.proppr.prove.wam.Query) WamProgram(edu.cmu.ml.proppr.prove.wam.WamProgram) StateProofGraph(edu.cmu.ml.proppr.prove.wam.StateProofGraph) APROptions(edu.cmu.ml.proppr.util.APROptions) File(java.io.File) Test(org.junit.Test) GrounderTest(edu.cmu.ml.proppr.GrounderTest) SparseGraphPluginTest(edu.cmu.ml.proppr.prove.wam.plugins.SparseGraphPluginTest)

Example 4 with WamPlugin

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

the class WamInterpreter method wamOutlinks.

/** Compute the list of children of an immutableState. 
	 * @throws LogicProgramException */
public List<Outlink> wamOutlinks(State s, boolean computeFeatures) throws LogicProgramException {
    if (s.isCompleted())
        return Collections.emptyList();
    List<Outlink> result = new ArrayList<Outlink>();
    for (WamPlugin plugin : this.plugins) {
        if (plugin.claim(s.getJumpTo())) {
            if (log.isDebugEnabled())
                log.debug("Executing " + s.getJumpTo() + " from " + plugin.about());
            this.restoreState(s);
            //if (log.isDebugEnabled()) log.debug(this.constantTable.toString());
            for (Outlink o : plugin.outlinks(s, this, computeFeatures)) {
                result.add(o);
            }
            return result;
        }
    }
    if (!this.program.hasLabel(s.getJumpTo()))
        throw new LogicProgramException("Unknown predicate " + s.getJumpTo());
    for (Integer address : program.getAddresses(s.getJumpTo())) {
        if (log.isDebugEnabled())
            log.debug("Executing " + s.getJumpTo() + " from " + address);
        this.restoreState(s);
        //if (log.isDebugEnabled()) log.debug(this.constantTable.toString());
        if (computeFeatures) {
            Map<Feature, Double> features = this.executeWithoutBranching(address);
            if (!features.isEmpty() && !this.state.isFailed()) {
                this.executeWithoutBranching();
                if (!this.state.isFailed()) {
                    result.add(new Outlink(features, this.saveState()));
                }
            }
        } else {
            this.executeWithoutBranching();
            result.add(new Outlink(null, this.saveState()));
        }
    }
    return result;
}
Also used : WamPlugin(edu.cmu.ml.proppr.prove.wam.plugins.WamPlugin) ArrayList(java.util.ArrayList)

Example 5 with WamPlugin

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

WamPlugin (edu.cmu.ml.proppr.prove.wam.plugins.WamPlugin)8 WamProgram (edu.cmu.ml.proppr.prove.wam.WamProgram)6 APROptions (edu.cmu.ml.proppr.util.APROptions)6 Query (edu.cmu.ml.proppr.prove.wam.Query)5 File (java.io.File)5 GroundedExample (edu.cmu.ml.proppr.examples.GroundedExample)4 InferenceExample (edu.cmu.ml.proppr.examples.InferenceExample)4 Prover (edu.cmu.ml.proppr.prove.Prover)4 StateProofGraph (edu.cmu.ml.proppr.prove.wam.StateProofGraph)4 Test (org.junit.Test)4 DprProver (edu.cmu.ml.proppr.prove.DprProver)3 StatusLogger (edu.cmu.ml.proppr.util.StatusLogger)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 ProofGraph (edu.cmu.ml.proppr.prove.wam.ProofGraph)2 State (edu.cmu.ml.proppr.prove.wam.State)2 GrounderTest (edu.cmu.ml.proppr.GrounderTest)1 DfsProver (edu.cmu.ml.proppr.prove.DfsProver)1 Argument (edu.cmu.ml.proppr.prove.wam.Argument)1