Search in sources :

Example 6 with WamProgram

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

the class WamProgramTest method testLoad.

@Test
public void testLoad() throws IOException {
    WamProgram program = WamBaseProgram.load(new File(SimpleProgramProverTest.PROGRAM));
    OP[] simpleProgram = { OP.comment, OP.allocate, OP.initfreevar, OP.initfreevar, OP.fclear, OP.fpushstart, OP.fpushconst, OP.fpushconst, OP.fpushconst, OP.freport, OP.pushboundvar, OP.pushfreevar, OP.callp, OP.pushboundvar, OP.pushboundvar, OP.callp, OP.returnp, OP.comment, OP.allocate, OP.initfreevar, OP.initfreevar, OP.fclear, OP.fpushstart, OP.fpushconst, OP.fpushconst, OP.fpushconst, OP.freport, OP.pushboundvar, OP.callp, OP.pushboundvar, OP.pushboundvar, OP.callp, OP.returnp, OP.comment, OP.unifyconst, OP.unifyconst, OP.fclear, OP.fpushstart, OP.fpushconst, OP.fpushconst, OP.fpushconst, OP.freport, OP.returnp, OP.comment, OP.unifyconst, OP.unifyconst, OP.fclear, OP.fpushstart, OP.fpushconst, OP.fpushconst, OP.fpushconst, OP.freport, OP.returnp, OP.comment, OP.unifyconst, OP.fclear, OP.fpushstart, OP.fpushconst, OP.fpushconst, OP.fpushconst, OP.freport, OP.returnp };
    assertEquals(simpleProgram.length, program.size());
    for (int i = 0; i < simpleProgram.length; i++) {
        assertEquals("Instruction " + i, simpleProgram[i], program.getInstruction(i).opcode);
    }
    assertTrue(program.hasLabel("coworker/2"));
    List<Integer> addr = program.getAddresses("coworker/2");
    assertEquals("coworker/2", 1, addr.get(0).intValue());
    assertTrue(program.hasLabel("employee/2"));
    addr = program.getAddresses(("employee/2"));
    assertEquals("employee/2", 18, addr.get(0).intValue());
}
Also used : OP(edu.cmu.ml.proppr.prove.wam.Instruction.OP) WamProgram(edu.cmu.ml.proppr.prove.wam.WamProgram) File(java.io.File) Test(org.junit.Test)

Example 7 with WamProgram

use of edu.cmu.ml.proppr.prove.wam.WamProgram 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 8 with WamProgram

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

the class TestNeqPlugin method test.

@Test
public void test() throws IOException, LogicProgramException {
    APROptions apr = new APROptions();
    WamProgram program = WamProgram.load(new File(PROGRAM));
    Query different = Query.parse("different(door,cat)");
    Query same = Query.parse("different(lake,lake)");
    Prover p = new DprProver(apr);
    StatusLogger s = new StatusLogger();
    assertEquals("different should have 1 solution", 1, p.solutions(new StateProofGraph(different, apr, program), s).size());
    assertEquals("same should have no solution", 0, p.solutions(new StateProofGraph(same, apr, program), s).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) APROptions(edu.cmu.ml.proppr.util.APROptions) File(java.io.File) Test(org.junit.Test)

Example 9 with WamProgram

use of edu.cmu.ml.proppr.prove.wam.WamProgram 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 10 with WamProgram

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

the class DuplicateSignatureRuleTest method test2.

@Test
public void test2() throws LogicProgramException, IOException {
    APROptions apr = new APROptions("depth=10");
    WamProgram program = WamBaseProgram.load(new File(PROGRAM));
    ProofGraph pg = new StateProofGraph(Query.parse("canExit(steve,X)"), apr, program);
    Prover p = new TracingDfsProver(apr);
    Map<Query, Double> result = p.solvedQueries(pg, new StatusLogger());
    for (Map.Entry<Query, Double> e : result.entrySet()) {
        System.out.println(e.getValue() + "\t" + e.getKey());
        assertEquals("Steve not allowed to exit " + e.getKey() + "\n", "canExit(steve,kitchen).", e.getKey().toString());
    }
}
Also used : TracingDfsProver(edu.cmu.ml.proppr.prove.TracingDfsProver) 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) Prover(edu.cmu.ml.proppr.prove.Prover) TracingDfsProver(edu.cmu.ml.proppr.prove.TracingDfsProver) 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) Map(java.util.Map) Test(org.junit.Test)

Aggregations

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