Search in sources :

Example 1 with Rewrite

use of suite.node.util.Rewrite 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);
}
Also used : Suite(suite.Suite) Singleton(suite.node.util.Singleton) Inspect(suite.inspect.Inspect) List_(suite.util.List_) To(suite.util.To) Chars(suite.primitive.Chars) Fun(suite.util.FunUtil.Fun) ArrayList(java.util.ArrayList) Node(suite.node.Node) CharsBuilder(suite.primitive.Chars.CharsBuilder) Iterate(suite.util.FunUtil.Iterate) List(java.util.List) ProverConstant(suite.lp.doer.ProverConstant) Rewrite(suite.node.util.Rewrite) Atom(suite.node.Atom) Nodify(suite.util.Nodify) Generalizer(suite.lp.doer.Generalizer) Dict(suite.node.Dict) Str(suite.node.Str) Str(suite.node.Str) Generalizer(suite.lp.doer.Generalizer) Dict(suite.node.Dict) Node(suite.node.Node)

Aggregations

ArrayList (java.util.ArrayList)1 List (java.util.List)1 Suite (suite.Suite)1 Inspect (suite.inspect.Inspect)1 Generalizer (suite.lp.doer.Generalizer)1 ProverConstant (suite.lp.doer.ProverConstant)1 Atom (suite.node.Atom)1 Dict (suite.node.Dict)1 Node (suite.node.Node)1 Str (suite.node.Str)1 Rewrite (suite.node.util.Rewrite)1 Singleton (suite.node.util.Singleton)1 Chars (suite.primitive.Chars)1 CharsBuilder (suite.primitive.Chars.CharsBuilder)1 Fun (suite.util.FunUtil.Fun)1 Iterate (suite.util.FunUtil.Iterate)1 List_ (suite.util.List_)1 Nodify (suite.util.Nodify)1 To (suite.util.To)1