Search in sources :

Example 1 with NodeRead

use of suite.node.io.Rewrite_.NodeRead in project suite by stupidsing.

the class Grapher method graph_.

private int graph_(Map<IdentityKey<Node>, Integer> ids, Node node) {
    IdentityKey<Node> key = IdentityKey.of(node);
    Integer id = ids.get(key);
    if (id == null) {
        ids.put(key, id = gns.size());
        gns.add(null);
        NodeRead nr = NodeRead.of(node);
        List<IntIntPair> children = // 
        Read.from(// 
        nr.children).map(// 
        p -> IntIntPair.of(graph_(ids, p.t0), graph_(ids, p.t1))).toList();
        gns.set(id, new GN(nr.type, nr.terminal, nr.op, children));
    }
    return id;
}
Also used : DataInputStream(java.io.DataInputStream) Read(suite.streamlet.Read) HashMap(java.util.HashMap) Deque(java.util.Deque) ArrayList(java.util.ArrayList) Node(suite.node.Node) HashSet(java.util.HashSet) ProverConstant(suite.lp.doer.ProverConstant) DataOutputStream(java.io.DataOutputStream) Map(java.util.Map) IdentityKey(suite.adt.IdentityKey) Binder(suite.lp.doer.Binder) Tuple(suite.node.Tuple) Dict(suite.node.Dict) Reference(suite.node.Reference) Trail(suite.lp.Trail) IntIntPair(suite.primitive.adt.pair.IntIntPair) Set(java.util.Set) IOException(java.io.IOException) NodeRead(suite.node.io.Rewrite_.NodeRead) NodeHead(suite.node.io.Rewrite_.NodeHead) IntObjMap(suite.primitive.adt.map.IntObjMap) Tree(suite.node.Tree) Objects(java.util.Objects) Pair(suite.adt.pair.Pair) List(java.util.List) Atom(suite.node.Atom) Entry(java.util.Map.Entry) As(suite.streamlet.As) ArrayDeque(java.util.ArrayDeque) Int(suite.node.Int) Fail(suite.util.Fail) Str(suite.node.Str) ReadType(suite.node.io.Rewrite_.ReadType) NodeRead(suite.node.io.Rewrite_.NodeRead) Node(suite.node.Node) IntIntPair(suite.primitive.adt.pair.IntIntPair)

Example 2 with NodeRead

use of suite.node.io.Rewrite_.NodeRead in project suite by stupidsing.

the class Lister method leaves.

private Streamlet<IList<Node>> leaves(Node node, IList<Node> prefix) {
    NodeRead nr = NodeRead.of(node);
    Streamlet<IList<Node>> st;
    if (nr.type == ReadType.TUPLE)
        st = // 
        Read.from(// 
        nr.children).index().map(// 
        (i, p) -> leaves(p.t1, IList.cons(Int.of(i), prefix))).collect(As::concat);
    else if (nr.type != ReadType.TERM)
        st = Read.from(nr.children).concatMap(p -> leaves(p.t1, IList.cons(p.t0, prefix)));
    else
        st = Read.from(List.of(IList.cons(nr.terminal, prefix)));
    if (nr.op != null)
        st = st.cons(IList.cons(Atom.of(nr.op.toString()), prefix));
    return st;
}
Also used : List(java.util.List) Read(suite.streamlet.Read) Streamlet(suite.streamlet.Streamlet) Atom(suite.node.Atom) As(suite.streamlet.As) IList(suite.immutable.IList) NodeRead(suite.node.io.Rewrite_.NodeRead) Int(suite.node.Int) Node(suite.node.Node) ReadType(suite.node.io.Rewrite_.ReadType) NodeRead(suite.node.io.Rewrite_.NodeRead) As(suite.streamlet.As) IList(suite.immutable.IList)

Aggregations

List (java.util.List)2 Atom (suite.node.Atom)2 Int (suite.node.Int)2 Node (suite.node.Node)2 NodeRead (suite.node.io.Rewrite_.NodeRead)2 ReadType (suite.node.io.Rewrite_.ReadType)2 As (suite.streamlet.As)2 Read (suite.streamlet.Read)2 DataInputStream (java.io.DataInputStream)1 DataOutputStream (java.io.DataOutputStream)1 IOException (java.io.IOException)1 ArrayDeque (java.util.ArrayDeque)1 ArrayList (java.util.ArrayList)1 Deque (java.util.Deque)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 Objects (java.util.Objects)1 Set (java.util.Set)1