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;
}
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));
}
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;
}
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);
}
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);
}
Aggregations