Search in sources :

Example 6 with WamPlugin

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

the class GrounderTest method noNegativeExamplesTest.

@Test
public void noNegativeExamplesTest() 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) };
    Prover p = new DprProver(apr);
    Grounder grounder = new Grounder(apr, p, program, plugins);
    InferenceExample ix = new InferenceExample(Query.parse("predict(howard,Y)"), new Query[] { Query.parse("predict(howard,bird)") }, new Query[] {});
    GroundedExample ex = grounder.groundExample(p, ix);
    makeAssertions(ex, "dpr+", 10, 23, 1.0, 1, "7", 0, "");
    ix = new InferenceExample(Query.parse("predict(howard,Y)"), new Query[] { Query.parse("predict(howard,bird)") }, new Query[] {});
    ProofGraph pg = p.makeProofGraph(ix, apr, program, plugins);
    State pos = null;
    Map<State, Double> sols = p.prove(pg, new StatusLogger());
    System.out.println(pg.serialize(ex));
}
Also used : StatusLogger(edu.cmu.ml.proppr.util.StatusLogger) 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) IdDprProver(edu.cmu.ml.proppr.prove.IdDprProver) PprProver(edu.cmu.ml.proppr.prove.PprProver) DprProver(edu.cmu.ml.proppr.prove.DprProver) IdPprProver(edu.cmu.ml.proppr.prove.IdPprProver) Prover(edu.cmu.ml.proppr.prove.Prover) IdDprProver(edu.cmu.ml.proppr.prove.IdDprProver) DprProver(edu.cmu.ml.proppr.prove.DprProver) WamProgram(edu.cmu.ml.proppr.prove.wam.WamProgram) InferenceExample(edu.cmu.ml.proppr.examples.InferenceExample) WamPlugin(edu.cmu.ml.proppr.prove.wam.plugins.WamPlugin) State(edu.cmu.ml.proppr.prove.wam.State) APROptions(edu.cmu.ml.proppr.util.APROptions) File(java.io.File) Test(org.junit.Test)

Example 7 with WamPlugin

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

the class GrounderTest method unboundLabelsTest.

@Test(expected = IllegalArgumentException.class)
public void unboundLabelsTest() 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) };
    Prover p = new DprProver(apr);
    Grounder grounder = new Grounder(apr, p, program, plugins);
    InferenceExample ix = new InferenceExample(Query.parse("predict(howard,Bird)"), new Query[] { Query.parse("predict(howard,Bird)") }, new Query[] {});
    GroundedExample ex = grounder.groundExample(p, ix);
}
Also used : WamPlugin(edu.cmu.ml.proppr.prove.wam.plugins.WamPlugin) GroundedExample(edu.cmu.ml.proppr.examples.GroundedExample) IdDprProver(edu.cmu.ml.proppr.prove.IdDprProver) PprProver(edu.cmu.ml.proppr.prove.PprProver) DprProver(edu.cmu.ml.proppr.prove.DprProver) IdPprProver(edu.cmu.ml.proppr.prove.IdPprProver) Prover(edu.cmu.ml.proppr.prove.Prover) IdDprProver(edu.cmu.ml.proppr.prove.IdDprProver) DprProver(edu.cmu.ml.proppr.prove.DprProver) 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) Test(org.junit.Test)

Example 8 with WamPlugin

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

the class ProofGraph method addBuiltinPlugins.

private WamPlugin[] addBuiltinPlugins(WamPlugin... plugins) {
    WamPlugin[] result = Arrays.copyOf(plugins, plugins.length + 1);
    FilterPluginCollection filters = new FilterPluginCollection(this.apr);
    result[plugins.length] = filters;
    filters.register("neq/2", new PluginFunction() {

        @Override
        public boolean run(WamInterpreter wamInterp) throws LogicProgramException {
            String arg1 = wamInterp.getConstantArg(2, 1);
            String arg2 = wamInterp.getConstantArg(2, 2);
            if (arg1 == null || arg2 == null)
                throw new LogicProgramException("cannot call neq/2 unless both variables are bound");
            return arg1 != arg2;
        }
    });
    return result;
}
Also used : PluginFunction(edu.cmu.ml.proppr.prove.wam.plugins.builtin.PluginFunction) WamPlugin(edu.cmu.ml.proppr.prove.wam.plugins.WamPlugin) FilterPluginCollection(edu.cmu.ml.proppr.prove.wam.plugins.builtin.FilterPluginCollection)

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