Search in sources :

Example 76 with Node

use of suite.node.Node 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 77 with Node

use of suite.node.Node in project suite by stupidsing.

the class IterativeParserTest method testParseAuto.

@Test
public void testParseAuto() {
    String in = FileUtil.read("src/main/ll/auto.sl");
    Node node = iterativeParser.parse(in);
    System.out.println(new PrettyPrinter().prettyPrint(node));
    assertNotNull(Tree.decompose(node));
}
Also used : PrettyPrinter(suite.node.pp.PrettyPrinter) Node(suite.node.Node) Test(org.junit.Test)

Example 78 with Node

use of suite.node.Node in project suite by stupidsing.

the class RecursiveFactorizerTest method rewriteNewArgument.

private String rewriteNewArgument(String pred0, String predx, String newArgument, String s0) {
    Source<Node[]> source = () -> {
        Reference[] r = new Reference[64];
        for (int i = 0; i < r.length; i++) r[i] = new Reference();
        Fun<String, Fun<Boolean, Node>> fun = hs -> b -> {
            Source<Node> g = To.source(r);
            Node head = terminalNode(hs);
            Node n0 = !b ? g.source() : operatorNode(TermOp.TUPLE_, List.of(g.source(), terminalNode(" "), terminalNode(newArgument)));
            Node n1 = operatorNode(g, TermOp.TUPLE_, g.source(), n0);
            return operatorNode(g, TermOp.TUPLE_, head, n1);
        };
        return new Node[] { fun.apply(pred0).apply(false), fun.apply(predx).apply(true) };
    };
    FactorizeResult fr0 = recursiveFactorizer.parse(s0);
    FNode fn0 = fr0.node;
    Node node0 = nodify.nodify(FNode.class, fn0);
    Node nodex = rw.rewrite(source, node0);
    FNode fnx = nodify.unnodify(FNode.class, nodex);
    FactorizeResult frx = new FactorizeResult(fr0.pre, fnx, fr0.post);
    String sx = frx.unparse();
    return sx;
}
Also used : Reference(suite.node.Reference) FNode(suite.node.parser.FactorizeResult.FNode) Node(suite.node.Node) FNode(suite.node.parser.FactorizeResult.FNode) Fun(suite.util.FunUtil.Fun)

Example 79 with Node

use of suite.node.Node in project suite by stupidsing.

the class RecursiveFactorizerTest method treeNode.

private Node treeNode(Source<Node> g, Node name, List<Node> nodes) {
    List<Node> pairs = Read.from(nodes).map(node -> pairNode(node, g.source())).toList();
    Dict dict = new Dict();
    dict.map.put(Atom.of("name"), Reference.of(name));
    dict.map.put(Atom.of("pairs"), Reference.of(Tree.of(TermOp.OR____, pairs)));
    return Tree.of(TermOp.COLON_, Atom.of(FTree.class.getName()), dict);
}
Also used : FNode(suite.node.parser.FactorizeResult.FNode) Read(suite.streamlet.Read) Singleton(suite.node.util.Singleton) Fun(suite.util.FunUtil.Fun) Node(suite.node.Node) FTree(suite.node.parser.FactorizeResult.FTree) FileUtil(suite.os.FileUtil) Nodify(suite.util.Nodify) Dict(suite.node.Dict) FPair(suite.node.parser.FactorizeResult.FPair) Reference(suite.node.Reference) Source(suite.util.FunUtil.Source) Assert.assertTrue(org.junit.Assert.assertTrue) TermOp(suite.node.io.TermOp) FTerminal(suite.node.parser.FactorizeResult.FTerminal) Test(org.junit.Test) To(suite.util.To) Tree(suite.node.Tree) Iterate(suite.util.FunUtil.Iterate) List(java.util.List) Rewrite(suite.node.util.Rewrite) Assert.assertFalse(org.junit.Assert.assertFalse) Atom(suite.node.Atom) Operator(suite.node.io.Operator) Assert.assertEquals(org.junit.Assert.assertEquals) Str(suite.node.Str) Dict(suite.node.Dict) FNode(suite.node.parser.FactorizeResult.FNode) Node(suite.node.Node)

Example 80 with Node

use of suite.node.Node in project suite by stupidsing.

the class SldResolutionTest method test.

@Test
public void test() {
    Node node = Suite.parse("AND (OR (VAR A) (VAR B)) (OR (NOT (VAR A)) (VAR C))");
    List<Node> results = new SldResolution().resolve(node);
    System.out.println(results);
    assertTrue(results != Atom.NIL);
}
Also used : Node(suite.node.Node) Test(org.junit.Test)

Aggregations

Node (suite.node.Node)139 Tree (suite.node.Tree)50 Reference (suite.node.Reference)41 Atom (suite.node.Atom)37 Int (suite.node.Int)33 ArrayList (java.util.ArrayList)32 Pair (suite.adt.pair.Pair)25 List (java.util.List)24 TermOp (suite.node.io.TermOp)21 Read (suite.streamlet.Read)21 Test (org.junit.Test)20 Map (java.util.Map)19 Suite (suite.Suite)18 Generalizer (suite.lp.doer.Generalizer)18 Fail (suite.util.Fail)18 Fun (suite.util.FunUtil.Fun)18 Str (suite.node.Str)17 Trail (suite.lp.Trail)16 RuleSet (suite.lp.kb.RuleSet)16 Tuple (suite.node.Tuple)16