diff options
Diffstat (limited to 'monkey')
-rw-r--r-- | monkey/edits.py | 78 | ||||
-rwxr-xr-x | monkey/test.py | 2 |
2 files changed, 1 insertions, 79 deletions
diff --git a/monkey/edits.py b/monkey/edits.py index 1b5633d..cf2bc66 100644 --- a/monkey/edits.py +++ b/monkey/edits.py @@ -243,84 +243,6 @@ def classify_edits(edits): changes[(before, after)] = cost return inserts, removes, changes -# Simplify an edit graph with given nodes: remove empty leaf nodes and other -# fluff. The function is called recursively until no more changes are done. -def clean_graph(nodes): - changed = False - - # A - # | --> A (when B is an empty leaf) - # B - for node in nodes: - if len(node.eout) == 0 and len(node.ein) == 1 and len(node.data[2]) == 0: - parent = node.ein[0] - parent.eout.remove(node) - nodes.remove(node) - changed = True - break - - # A - # | --> A - # A - for node in nodes: - if len(node.ein) == 1: - parent = node.ein[0] - if len(parent.eout) == 1 and node.data[2] == parent.data[2]: - parent.eout = node.eout - for child in parent.eout: - child.ein = [parent if node == node else node for node in child.ein] - nodes.remove(node) - changed = True - break - - # A A - # |\ | - # | C --> | (when C is empty) - # |/ | - # B B - for node in nodes: - if len(node.data[2]) == 0 and len(node.ein) == 1 and len(node.eout) == 1: - parent = node.ein[0] - child = node.eout[0] - if len(parent.eout) == 2 and len(child.ein) == 2: - parent.eout = [n for n in parent.eout if n != node] - child.ein = [n for n in child.ein if n != node] - nodes.remove(node) - changed = True - break - - # A - # | - # C --> A - # | - # A - for node in nodes: - if len(node.data[2]) == 0 and len(node.ein) == 1 and len(node.eout) == 1: - parent = node.ein[0] - child = node.eout[0] - if len(parent.eout) == 1 and len(child.ein) == 1 and parent.data[2] == child.data[2]: - parent.eout = [child] - child.ein = [parent] - nodes.remove(node) - changed = True - break - - if changed: - # go again until nothing changes - clean_graph(nodes) - else: - # compact node ranks - ranks = set([node.data[0] for node in nodes]) - missing = set(range(1,max(ranks)+1)) - ranks - - for node in nodes: - diff = 0 - for rank in sorted(missing): - if rank >= node.data[0]: - break - diff += 1 - node.data[0] -= diff - if __name__ == '__main__': import os import pickle diff --git a/monkey/test.py b/monkey/test.py index 16d635f..eb91e3c 100755 --- a/monkey/test.py +++ b/monkey/test.py @@ -12,7 +12,7 @@ from .edits import classify_edits, edit_graph, get_edits_from_traces from .graph import graphviz from .monkey import fix from prolog.engine import test -from prolog.util import Token, compose, decompose, stringify +from prolog.util import Token, compose, decompose, stringify from .util import indent # Load django models. |