Search in sources :

Example 1 with ProverFactory

use of suite.lp.doer.ProverFactory in project suite by stupidsing.

the class SewingProverBuilder method build.

@Override
public Fun<Node, Finder> build(RuleSet ruleSet) {
    ProverFactory sewingProver = new SewingProverImpl(ruleSet);
    return goal -> {
        Node goal1 = SewingGeneralizerImpl.generalize(goal);
        Prove_ pred = sewingProver.prover(goal1);
        return (source, sink) -> {
            ProverConfig proverConfig1 = new ProverConfig(ruleSet, proverConfig);
            proverConfig1.setSource(source);
            proverConfig1.setSink(sink);
            pred.test(proverConfig1);
        };
    };
}
Also used : SewingGeneralizerImpl(suite.lp.sewing.impl.SewingGeneralizerImpl) SewingProverImpl(suite.lp.sewing.impl.SewingProverImpl) Finder(suite.lp.search.ProverBuilder.Finder) ProverFactory(suite.lp.doer.ProverFactory) Builder(suite.lp.search.ProverBuilder.Builder) Prove_(suite.lp.doer.ProverFactory.Prove_) RuleSet(suite.lp.kb.RuleSet) Fun(suite.util.FunUtil.Fun) ProverConfig(suite.lp.Configuration.ProverConfig) Node(suite.node.Node) Node(suite.node.Node) ProverConfig(suite.lp.Configuration.ProverConfig) Prove_(suite.lp.doer.ProverFactory.Prove_) ProverFactory(suite.lp.doer.ProverFactory) SewingProverImpl(suite.lp.sewing.impl.SewingProverImpl)

Example 2 with ProverFactory

use of suite.lp.doer.ProverFactory in project suite by stupidsing.

the class SewingProverTest method testPerformance.

@Test
public void testPerformance() {
    RuleSet rs = Suite.newRuleSet();
    Atom pred = Atom.of("q");
    Atom tail = Atom.NIL;
    for (int i = 0; i < 65536; i++) rs.addRule(Rule.of(Tree.of(TermOp.IS____, Tree.of(TermOp.TUPLE_, pred, Int.of(i)), tail)));
    ProverFactory sp = new SewingProverImpl(rs);
    ProverConfig pc = new ProverConfig(rs);
    Prove_ test = sp.prover(Suite.parse("q 32768"));
    Source<Stopwatch<Boolean>> trial = () -> Stopwatch.of(() -> {
        boolean isOk = true;
        for (int i = 0; i < 65536; i++) isOk &= test.test(pc);
        assertTrue(isOk);
        return isOk;
    });
    for (int i = 0; i < 8; i++) trial.source();
    Stopwatch<Boolean> sw = trial.source();
    System.out.println(sw.duration);
    assertTrue(sw.duration < 300);
}
Also used : RuleSet(suite.lp.kb.RuleSet) ProverConfig(suite.lp.Configuration.ProverConfig) Stopwatch(suite.os.Stopwatch) Prove_(suite.lp.doer.ProverFactory.Prove_) Atom(suite.node.Atom) ProverFactory(suite.lp.doer.ProverFactory) SewingProverImpl(suite.lp.sewing.impl.SewingProverImpl) Test(org.junit.Test)

Example 3 with ProverFactory

use of suite.lp.doer.ProverFactory in project suite by stupidsing.

the class SewingProverTest method testBacktrack.

@Test
public void testBacktrack() {
    RuleSet rs = Suite.newRuleSet();
    Suite.addRule(rs, "mem (.e, _) .e");
    Suite.addRule(rs, "mem (_, .tail) .e :- mem .tail .e");
    Suite.addRule(rs, "q .c .v :- once (mem (0,) .v), .a/.b/.c = 0/0/0; mem (1,) .v, .a/.b/.c = 1/1/1");
    Suite.addRule(rs, "r .c :- q .c .v, .v = 1");
    ProverFactory sp = new SewingProverImpl(rs);
    ProverConfig pc = new ProverConfig(rs);
    assertTrue(sp.prover(new Generalizer().generalize(Suite.parse("r .c"))).test(pc));
}
Also used : RuleSet(suite.lp.kb.RuleSet) Generalizer(suite.lp.doer.Generalizer) ProverConfig(suite.lp.Configuration.ProverConfig) ProverFactory(suite.lp.doer.ProverFactory) SewingProverImpl(suite.lp.sewing.impl.SewingProverImpl) Test(org.junit.Test)

Example 4 with ProverFactory

use of suite.lp.doer.ProverFactory in project suite by stupidsing.

the class SewingProverTest method testIf.

@Test
public void testIf() {
    RuleSet rs = Suite.newRuleSet();
    ProverFactory sp = new SewingProverImpl(rs);
    ProverConfig pc = new ProverConfig(rs);
    assertTrue(sp.prover(Suite.parse("if () () fail")).test(pc));
    assertFalse(sp.prover(Suite.parse("if () fail ()")).test(pc));
    assertTrue(sp.prover(Suite.parse("if fail fail ()")).test(pc));
    assertFalse(sp.prover(Suite.parse("if fail () fail")).test(pc));
}
Also used : RuleSet(suite.lp.kb.RuleSet) ProverConfig(suite.lp.Configuration.ProverConfig) ProverFactory(suite.lp.doer.ProverFactory) SewingProverImpl(suite.lp.sewing.impl.SewingProverImpl) Test(org.junit.Test)

Example 5 with ProverFactory

use of suite.lp.doer.ProverFactory in project suite by stupidsing.

the class SewingProverTest method test.

@Test
public void test() {
    RuleSet rs = Suite.newRuleSet();
    Suite.addRule(rs, "yes");
    ProverFactory sp = new SewingProverImpl(rs);
    ProverConfig pc = new ProverConfig(rs);
    assertTrue(sp.prover(Suite.parse("yes")).test(pc));
    assertTrue(sp.prover(Suite.parse("fail; yes")).test(pc));
    assertTrue(sp.prover(Suite.parse("yes; yes")).test(pc));
    assertFalse(sp.prover(Suite.parse("yes, fail")).test(pc));
    assertFalse(sp.prover(Suite.parse("!, fail; yes")).test(pc));
    assertTrue(sp.prover(new Generalizer().generalize(Suite.parse("(.v = 1; .v = 2), .v = 2"))).test(pc));
    assertFalse(sp.prover(new Generalizer().generalize(Suite.parse("once (.v = 1; .v = 2), .v = 2"))).test(pc));
    assertFalse(sp.prover(Suite.parse("not yes")).test(pc));
    assertTrue(sp.prover(Suite.parse("not fail")).test(pc));
    assertTrue(sp.prover(new Generalizer().generalize(Suite.parse(".p = yes, .p"))).test(pc));
}
Also used : RuleSet(suite.lp.kb.RuleSet) Generalizer(suite.lp.doer.Generalizer) ProverConfig(suite.lp.Configuration.ProverConfig) ProverFactory(suite.lp.doer.ProverFactory) SewingProverImpl(suite.lp.sewing.impl.SewingProverImpl) Test(org.junit.Test)

Aggregations

ProverConfig (suite.lp.Configuration.ProverConfig)7 ProverFactory (suite.lp.doer.ProverFactory)7 RuleSet (suite.lp.kb.RuleSet)7 SewingProverImpl (suite.lp.sewing.impl.SewingProverImpl)7 Test (org.junit.Test)6 Generalizer (suite.lp.doer.Generalizer)2 Prove_ (suite.lp.doer.ProverFactory.Prove_)2 Builder (suite.lp.search.ProverBuilder.Builder)1 Finder (suite.lp.search.ProverBuilder.Finder)1 SewingGeneralizerImpl (suite.lp.sewing.impl.SewingGeneralizerImpl)1 Atom (suite.node.Atom)1 Node (suite.node.Node)1 Stopwatch (suite.os.Stopwatch)1 Fun (suite.util.FunUtil.Fun)1