Search in sources :

Example 11 with StateProofGraph

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

the class EqualityTest method test.

@Test
public void test() throws LogicProgramException, IOException {
    WamProgram program = WamBaseProgram.load(new File(EQUALITY_PROGRAM));
    Prover prover = new DprProver();
    ProofGraph moral = new StateProofGraph(Query.parse("moral(X)"), new APROptions(), program);
    Collection<Query> bobs = prover.solvedQueries(moral, new StatusLogger()).keySet();
    //		Map<State,Double> ans = prover.prove(moral);
    //		ArrayList<Query> bobs = new ArrayList<Query>();
    //		for (Map.Entry<State,Double> e : ans.entrySet()) {
    //			if (e.getKey().isCompleted()) bobs.add(moral.fill(e.getKey()));
    //		}
    assertEquals(1, bobs.size());
    Query bob = bobs.iterator().next();
    assertEquals(1, bob.getRhs().length);
    assertEquals("Answer should be bob", "bob", bob.getRhs()[0].getArg(0).getName());
}
Also used : StatusLogger(edu.cmu.ml.proppr.util.StatusLogger) 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) APROptions(edu.cmu.ml.proppr.util.APROptions) File(java.io.File) Test(org.junit.Test)

Example 12 with StateProofGraph

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

the class PathDprProver method main.

public static void main(String[] args) throws LogicProgramException {
    CustomConfiguration c = new CustomConfiguration(args, //input
    Configuration.USE_PARAMS, //output
    0, //constants
    Configuration.USE_WAM | Configuration.USE_SQUASHFUNCTION, //modules
    0) {

        String query;

        @Override
        protected void addCustomOptions(Options options, int[] flags) {
            options.getOption(Configuration.PARAMS_FILE_OPTION).setRequired(false);
            options.addOption(OptionBuilder.withLongOpt("query").withArgName("functor(arg1,Var1)").hasArg().isRequired().withDescription("specify query to print top paths for").create());
        //TODO: add prompt option (for large datasets)
        }

        @Override
        protected void retrieveCustomSettings(CommandLine line, int[] flags, Options options) {
            query = line.getOptionValue("query");
        }

        @Override
        public Object getCustomSetting(String name) {
            return query;
        }
    };
    PathDprProver p = new PathDprProver(c.apr);
    Query query = Query.parse((String) c.getCustomSetting(null));
    StateProofGraph pg = new StateProofGraph(query, c.apr, c.program, c.plugins);
    p.prove(pg, new StatusLogger());
}
Also used : StatusLogger(edu.cmu.ml.proppr.util.StatusLogger) Options(org.apache.commons.cli.Options) APROptions(edu.cmu.ml.proppr.util.APROptions) CommandLine(org.apache.commons.cli.CommandLine) Query(edu.cmu.ml.proppr.prove.wam.Query) CustomConfiguration(edu.cmu.ml.proppr.util.CustomConfiguration) StateProofGraph(edu.cmu.ml.proppr.prove.wam.StateProofGraph)

Example 13 with StateProofGraph

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

the class WeightedRulesTest method test.

@Test
public void test() throws IOException, LogicProgramException {
    APROptions apr = new APROptions();
    Prover p = new DprProver(apr);
    WamProgram program = WamBaseProgram.load(RULES);
    WamPlugin[] plugins = new WamPlugin[] { FactsPlugin.load(apr, FACTS, false) };
    Grounder grounder = new Grounder(apr, p, program, plugins);
    assertTrue(plugins[0].claim("ruleWeight#/2"));
    Query query = Query.parse("shoppingList(X)");
    ProofGraph pg = new StateProofGraph(new InferenceExample(query, new Query[] { Query.parse("shoppingList(kidney_beans)") }, new Query[] { Query.parse("shoppingList(cinnamon)") }), 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);
    assertTrue("Rule weights must appear in ground graph (2.0)", serialized.indexOf("2.0") >= 0);
    assertTrue("Rule weights must appear in ground graph (3.0)", serialized.indexOf("3.0") >= 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 14 with StateProofGraph

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

the class SimpleProgramProverTest method test.

@Test
public void test() throws IOException, LogicProgramException {
    WamProgram program = WamBaseProgram.load(new File(PROGRAM));
    Query q = new Query(new Goal("coworker", new ConstantArgument("steve"), new ConstantArgument("X")));
    System.out.println("Query: " + q.toString());
    ProofGraph p = new StateProofGraph(q, apr, program);
    Prover prover = new DfsProver(apr);
    Map<String, Double> sols = prover.solutions(p, new StatusLogger());
    assertEquals(2, sols.size());
    HashMap<String, Integer> expected = new HashMap<String, Integer>();
    expected.put("steve", 0);
    expected.put("sven", 0);
    System.out.println("Query: " + q.toString());
    for (String pair : sols.keySet()) {
        System.out.println(pair);
        String[] parts = pair.split(":");
        String v = parts[1];
        System.out.println("Got solution: " + v);
        if (expected.containsKey(v))
            expected.put(v, expected.get(v) + 1);
    }
    for (Map.Entry<String, Integer> e : expected.entrySet()) assertEquals(e.getKey(), 1, e.getValue().intValue());
}
Also used : StatusLogger(edu.cmu.ml.proppr.util.StatusLogger) Query(edu.cmu.ml.proppr.prove.wam.Query) StateProofGraph(edu.cmu.ml.proppr.prove.wam.StateProofGraph) ProofGraph(edu.cmu.ml.proppr.prove.wam.ProofGraph) HashMap(java.util.HashMap) 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) Goal(edu.cmu.ml.proppr.prove.wam.Goal) DfsProver(edu.cmu.ml.proppr.prove.DfsProver) File(java.io.File) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 15 with StateProofGraph

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

Aggregations

StateProofGraph (edu.cmu.ml.proppr.prove.wam.StateProofGraph)18 Query (edu.cmu.ml.proppr.prove.wam.Query)17 WamProgram (edu.cmu.ml.proppr.prove.wam.WamProgram)15 Test (org.junit.Test)15 Prover (edu.cmu.ml.proppr.prove.Prover)13 APROptions (edu.cmu.ml.proppr.util.APROptions)13 ProofGraph (edu.cmu.ml.proppr.prove.wam.ProofGraph)10 DprProver (edu.cmu.ml.proppr.prove.DprProver)9 StatusLogger (edu.cmu.ml.proppr.util.StatusLogger)9 File (java.io.File)9 GroundedExample (edu.cmu.ml.proppr.examples.GroundedExample)6 InferenceExample (edu.cmu.ml.proppr.examples.InferenceExample)6 Feature (edu.cmu.ml.proppr.prove.wam.Feature)6 Grounder (edu.cmu.ml.proppr.Grounder)5 ConstantArgument (edu.cmu.ml.proppr.prove.wam.ConstantArgument)4 Goal (edu.cmu.ml.proppr.prove.wam.Goal)4 Map (java.util.Map)4 DfsProver (edu.cmu.ml.proppr.prove.DfsProver)3 State (edu.cmu.ml.proppr.prove.wam.State)3 WamPlugin (edu.cmu.ml.proppr.prove.wam.plugins.WamPlugin)3