Search in sources :

Example 1 with CompiledProverBuilder

use of suite.lp.search.CompiledProverBuilder 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)

Aggregations

ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 ProverConfig (suite.lp.Configuration.ProverConfig)1 RuleSet (suite.lp.kb.RuleSet)1 CompiledProverBuilder (suite.lp.search.CompiledProverBuilder)1 Finder (suite.lp.search.ProverBuilder.Finder)1 Node (suite.node.Node)1 Source (suite.util.FunUtil.Source)1