use of suite.node.Dict in project suite by stupidsing.
the class Grapher method ungraph_.
private Node ungraph_(int id) {
int size = gns.size();
List<Node> nodes = //
Read.from(//
gns).map(gn -> {
switch(gn.type) {
case DICT:
return new Dict();
case TERM:
return gn.terminal;
case TREE:
return Tree.of(gn.op, null, null);
case TUPLE:
return Tuple.of(new Node[gn.children.size()]);
default:
return Fail.t();
}
}).toList();
for (int i = 0; i < size; i++) {
GN gn = gns.get(i);
Node node = nodes.get(i);
List<Pair<Node, Node>> children = Read.from(gn.children).map(p -> Pair.of(nodes.get(p.t0), nodes.get(p.t1))).toList();
switch(gn.type) {
case DICT:
((Dict) node).map.putAll(Read.from2(children).mapValue(Reference::of).collect(As::map));
break;
case TERM:
break;
case TREE:
Tree tree = (Tree) node;
Tree.forceSetLeft(tree, children.get(0).t1);
Tree.forceSetRight(tree, children.get(1).t1);
break;
case TUPLE:
Node[] list = ((Tuple) node).nodes;
for (int j = 0; j < children.size(); j++) list[j] = children.get(j).t1;
}
}
return nodes.get(id);
}
use of suite.node.Dict in project suite by stupidsing.
the class FactorizeResult method rewrite.
public static FactorizeResult rewrite(FactorizeResult frfrom, FactorizeResult frto, FactorizeResult fr0) {
Generalizer generalizer = new Generalizer();
Iterate<Node> rewrite = n0 -> {
Node[] m = Suite.pattern(FTerminal.class.getName() + ":.0").match(n0);
Node n1 = m != null ? m[0] : null;
Node n2 = n1 instanceof Dict ? ((Dict) n1).map.get(Atom.of("chars")) : null;
Node n3 = n2 != null ? n2.finalNode() : null;
String s = n3 instanceof Str ? ((Str) n3).value : null;
boolean b = s != null && s.startsWith(ProverConstant.variablePrefix) && s.substring(1).matches("[0-9]*");
return b ? generalizer.generalize(Atom.of(s)) : n0;
};
Fun<FactorizeResult, Node> parse = fr -> rw.rewrite(rewrite, nodify.nodify(FNode.class, fr.node));
Node nodeFrom = parse.apply(frfrom);
Node nodeTo = parse.apply(frto);
FNode fn0 = fr0.node;
Node node0 = nodify.nodify(FNode.class, fn0);
Node nodex = rw.rewrite(nodeFrom, nodeTo, node0);
FNode fnx = nodify.unnodify(FNode.class, nodex);
return new FactorizeResult(fr0.pre, fnx, fr0.post);
}
Aggregations