Search in sources :

Example 11 with RuleSet

use of suite.lp.kb.RuleSet in project suite by stupidsing.

the class ProverTest method testAppend.

@Test
public void testAppend() {
    RuleSet rs = Suite.newRuleSet();
    Suite.addRule(rs, "app () .l .l");
    Suite.addRule(rs, "app (.h, .r) .l (.h, .r1) :- app .r .l .r1");
    assertTrue(test(rs, "app (a, b, c,) (d, e,) (a, b, c, d, e,)"));
}
Also used : RuleSet(suite.lp.kb.RuleSet) Test(org.junit.Test)

Example 12 with RuleSet

use of suite.lp.kb.RuleSet in project suite by stupidsing.

the class ProverTest method testTree.

@Test
public void testTree() {
    RuleSet rs = Suite.newRuleSet();
    assertFalse(test(rs, "tree .t0 a ':' b, tree .t1 a ':' b, same .t0 .t1"));
    assertTrue(test(rs, "intern.tree .t0 a ':' b, intern.tree .t1 a ':' b, same .t0 .t1"));
}
Also used : RuleSet(suite.lp.kb.RuleSet) Test(org.junit.Test)

Example 13 with RuleSet

use of suite.lp.kb.RuleSet in project suite by stupidsing.

the class RbTreeTest method test.

@Test
public void test() throws IOException {
    RuleSet rs = Suite.newRuleSet(List.of("auto.sl", "rbt.sl"));
    String gs = // 
    "" + // 
    "rbt-insert-list (6, 7, 8, 9, 10, 1, 2, 3, 4, 5,) ()/.t \n" + // 
    ", rbt-get .t 8" + ", rbt-member .t 4";
    for (Builder builder : List.of(new InterpretedProverBuilder(), new SewingProverBuilder2())) assertTrue(Suite.proveLogic(builder, rs, gs));
}
Also used : RuleSet(suite.lp.kb.RuleSet) InterpretedProverBuilder(suite.lp.search.InterpretedProverBuilder) InterpretedProverBuilder(suite.lp.search.InterpretedProverBuilder) Builder(suite.lp.search.ProverBuilder.Builder) SewingProverBuilder2(suite.lp.search.SewingProverBuilder2) Test(org.junit.Test)

Example 14 with RuleSet

use of suite.lp.kb.RuleSet 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 15 with RuleSet

use of suite.lp.kb.RuleSet 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)

Aggregations

RuleSet (suite.lp.kb.RuleSet)34 Test (org.junit.Test)25 ProverConfig (suite.lp.Configuration.ProverConfig)12 Node (suite.node.Node)9 ProverFactory (suite.lp.doer.ProverFactory)7 Builder (suite.lp.search.ProverBuilder.Builder)7 SewingProverImpl (suite.lp.sewing.impl.SewingProverImpl)7 Finder (suite.lp.search.ProverBuilder.Finder)6 Fun (suite.util.FunUtil.Fun)4 CompiledProverBuilder (suite.lp.search.CompiledProverBuilder)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Suite (suite.Suite)2 Prove_ (suite.lp.doer.ProverFactory.Prove_)2 Source (suite.util.FunUtil.Source)2 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 Collectors (java.util.stream.Collectors)1 Pattern (suite.BindArrayUtil.Pattern)1