Search in sources :

Example 16 with ProverConfig

use of suite.lp.Configuration.ProverConfig in project suite by stupidsing.

the class SewingProverTest method testCut.

@Test
public void testCut() {
    RuleSet rs = Suite.newRuleSet();
    Suite.addRule(rs, "a :- b");
    Suite.addRule(rs, "a");
    Suite.addRule(rs, "b :- !, fail");
    ProverFactory sp = new SewingProverImpl(rs);
    ProverConfig pc = new ProverConfig(rs);
    assertTrue(sp.prover(Suite.parse("a")).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 17 with ProverConfig

use of suite.lp.Configuration.ProverConfig in project suite by stupidsing.

the class SewingProverTest method testEnv.

@Test
public void testEnv() {
    RuleSet rs = Suite.newRuleSet();
    Suite.addRule(rs, "a :- b .a, b .b");
    Suite.addRule(rs, "b 1");
    ProverFactory sp = new SewingProverImpl(rs);
    ProverConfig pc = new ProverConfig(rs);
    assertTrue(sp.prover(Suite.parse("a")).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 18 with ProverConfig

use of suite.lp.Configuration.ProverConfig in project suite by stupidsing.

the class SldResolution method resolve.

public List<Node> resolve(Node node) {
    RuleSet ruleSet = Suite.newRuleSet(List.of("auto.sl", "pt.sl"));
    CompiledProverBuilder builder = CompiledProverBuilder.level1(new ProverConfig());
    Finder finder = builder.build(ruleSet).apply(Suite.parse(// 
    "" + // 
    "source .n0" + // 
    ", pt-prove0 .n0 .n1" + // 
    ", pt-prove1 .n1 .n2" + // 
    ", pt-prove2 .n2 .n3" + // 
    ", pt-prove3 .n3 .n4" + // 
    ", pt-prove4 .n4 .n5" + // 
    ", pt-prove5 .n5 ()/.n6" + ", sink .n6"));
    Node n0 = FindUtil.collectSingle(finder, node);
    Map<Node, Source<List<Node>>> orsMap = new HashMap<>();
    for (Node n1 : Tree.iter(n0, TermOp.AND___)) {
        List<Node> ors = To.list(Tree.iter(n1, TermOp.AND___));
        for (int i = 0; i < ors.size(); i++) {
            int index = i;
            orsMap.put(ors.get(index), () -> List_.concat(ors.subList(0, index), ors.subList(index + 1, ors.size())));
        }
    }
    List<Node> results = new ArrayList<>();
    for (Entry<Node, Source<List<Node>>> e : orsMap.entrySet()) {
        Source<List<Node>> value0 = e.getValue();
        Source<List<Node>> value1 = orsMap.get(negate(e.getKey()));
        if (value1 != null)
            results.add(Tree.of(TermOp.AND___, List_.concat(value0.source(), value1.source())));
    }
    return results;
}
Also used : RuleSet(suite.lp.kb.RuleSet) HashMap(java.util.HashMap) Node(suite.node.Node) Finder(suite.lp.search.ProverBuilder.Finder) ArrayList(java.util.ArrayList) Source(suite.util.FunUtil.Source) ProverConfig(suite.lp.Configuration.ProverConfig) ArrayList(java.util.ArrayList) List(java.util.List) CompiledProverBuilder(suite.lp.search.CompiledProverBuilder)

Example 19 with ProverConfig

use of suite.lp.Configuration.ProverConfig in project suite by stupidsing.

the class NodifyTest method testMapify.

@Test
public void testMapify() {
    ProverConfig pc0 = new ProverConfig();
    pc0.setRuleSet(null);
    Node node = nodify.nodify(ProverConfig.class, pc0);
    assertNotNull(node);
    System.out.println(node);
    ProverConfig pc1 = nodify.unnodify(ProverConfig.class, node);
    System.out.println(pc1);
    assertEquals(pc0, pc1);
    assertTrue(pc0.hashCode() == pc1.hashCode());
}
Also used : Node(suite.node.Node) ProverConfig(suite.lp.Configuration.ProverConfig) Test(org.junit.Test)

Example 20 with ProverConfig

use of suite.lp.Configuration.ProverConfig in project suite by stupidsing.

the class CompiledProverBuilder method build.

@Override
public Fun<Node, Finder> build(RuleSet ruleSet) {
    Node rules = Suite.getRules(ruleSet);
    return goal -> {
        Node code = compile(Suite.substitute(".0 >> .1", rules, goal));
        return (source, sink) -> {
            ProverConfig proverConfig1 = new ProverConfig(ruleSet, proverConfig);
            proverConfig1.setSource(source);
            proverConfig1.setSink(sink);
            try (InstructionExecutor executor = new LogicInstructionExecutor(code, proverConfig1)) {
                executor.execute();
            }
        };
    };
}
Also used : Suite(suite.Suite) InstructionExecutor(suite.instructionexecutor.InstructionExecutor) LogUtil(suite.os.LogUtil) Finder(suite.lp.search.ProverBuilder.Finder) LogicInstructionExecutor(suite.instructionexecutor.LogicInstructionExecutor) Builder(suite.lp.search.ProverBuilder.Builder) RuleSet(suite.lp.kb.RuleSet) Fun(suite.util.FunUtil.Fun) ProverConfig(suite.lp.Configuration.ProverConfig) Node(suite.node.Node) Node(suite.node.Node) InstructionExecutor(suite.instructionexecutor.InstructionExecutor) LogicInstructionExecutor(suite.instructionexecutor.LogicInstructionExecutor) ProverConfig(suite.lp.Configuration.ProverConfig) LogicInstructionExecutor(suite.instructionexecutor.LogicInstructionExecutor)

Aggregations

ProverConfig (suite.lp.Configuration.ProverConfig)21 RuleSet (suite.lp.kb.RuleSet)12 Test (org.junit.Test)10 SewingProverImpl (suite.lp.sewing.impl.SewingProverImpl)9 ProverFactory (suite.lp.doer.ProverFactory)8 Node (suite.node.Node)7 Builder (suite.lp.search.ProverBuilder.Builder)5 Finder (suite.lp.search.ProverBuilder.Finder)5 Fun (suite.util.FunUtil.Fun)4 Prove_ (suite.lp.doer.ProverFactory.Prove_)3 CompiledProverBuilder (suite.lp.search.CompiledProverBuilder)3 Generalizer (suite.lp.doer.Generalizer)2 Prover (suite.lp.doer.Prover)2 InterpretedProverBuilder (suite.lp.search.InterpretedProverBuilder)2 SewingGeneralizerImpl (suite.lp.sewing.impl.SewingGeneralizerImpl)2 PrintWriter (java.io.PrintWriter)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1