Search in sources :

Example 1 with RuleSet

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

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

the class SewingProverBuilder2 method build.

@Override
public Fun<Node, Finder> build(RuleSet ruleSet) {
    boolean isRewrite = !proverConfig.isTrace();
    QueryRewriter qr = isRewrite ? new QueryRewriter(Prototype.multimap(ruleSet)) : null;
    RuleSet ruleSet1;
    if (qr != null) {
        ruleSet1 = Suite.newRuleSet();
        qr.rules().entries().forEach(p -> ruleSet1.addRule(p.t1));
    } else
        ruleSet1 = ruleSet;
    Fun<Node, Finder> fun = new SewingProverBuilder(proverConfig).build(ruleSet1);
    if (qr != null)
        return goal -> fun.apply(qr.rewriteClause(goal));
    else
        return fun;
}
Also used : RuleSet(suite.lp.kb.RuleSet) QueryRewriter(suite.lp.sewing.impl.QueryRewriter) Node(suite.node.Node) Finder(suite.lp.search.ProverBuilder.Finder)

Example 3 with RuleSet

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

the class FailedTests method testRepeat.

// (Expected) infinite loop.
// (Actual) short boolean evaluation in Prover skipped the loop:
// alt = andTree(bt, orTree(andTree(right, rem), alt));
@Test
public void testRepeat() throws IOException {
    RuleSet rs = Suite.newRuleSet();
    Suite.importPath(rs, "auto.sl");
    assertTrue(Suite.proveLogic(rs, "repeat, fail"));
}
Also used : RuleSet(suite.lp.kb.RuleSet) FunRbTreeTest(suite.fp.FunRbTreeTest) Test(org.junit.Test)

Example 4 with RuleSet

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

the class LogicCompilerLevel1Test method testMemberOfMember.

@Test
public void testMemberOfMember() {
    RuleSet rs = Suite.newRuleSet(List.of("auto.sl"));
    Node goal = Suite.parse("source .lln, member .lln .ln, member .ln .n, sink .n");
    Node input = Suite.parse("((1, 2,), (3, 4,),)");
    List<Node> results = FindUtil.collectList(finder(rs, goal), input);
    System.out.println(results);
    assertTrue(results.size() == 4);
}
Also used : RuleSet(suite.lp.kb.RuleSet) Node(suite.node.Node) Test(org.junit.Test)

Example 5 with RuleSet

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

the class LogicCompilerLevel2Test method test0.

// require tail recursion to work
@Test
public void test0() {
    RuleSet rs = Suite.getRuleSet(Suite.parse(// 
    "" + // 
    "member (.e, _) .e #" + // 
    "member (_, .tail) .e :- member .tail .e #" + // 
    "sum .a .b .c :- bound .a, bound .b, let .c (.a - .b) #" + // 
    "sum .a .b .c :- bound .a, bound .c, let .b (.a - .c) #" + // 
    "sum .a .b .c :- bound .b, bound .c, let .a (.b + .c) #"));
    Builder builder = CompiledProverBuilder.level2(new ProverConfig());
    Suite.evaluateLogic(builder, rs, "(), sink ()");
}
Also used : RuleSet(suite.lp.kb.RuleSet) Builder(suite.lp.search.ProverBuilder.Builder) CompiledProverBuilder(suite.lp.search.CompiledProverBuilder) ProverConfig(suite.lp.Configuration.ProverConfig) 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