summaryrefslogtreecommitdiff
path: root/monkey/edits.py
diff options
context:
space:
mode:
authorTimotej Lazar <timotej.lazar@araneo.org>2015-02-18 17:33:07 +0100
committerAleš Smodiš <aless@guru.si>2015-08-11 14:26:02 +0200
commit072c34e650e7da475b7001b766c952ee9258db02 (patch)
tree8efcae2e0046183b32015829cd42fc612fb7f01c /monkey/edits.py
parent63ed3cceec22c354887fbdea398ca322d149bca0 (diff)
Rename monkey.edits.edit_graph to trace_graph
Diffstat (limited to 'monkey/edits.py')
-rw-r--r--monkey/edits.py34
1 files changed, 18 insertions, 16 deletions
diff --git a/monkey/edits.py b/monkey/edits.py
index cf2bc66..f34f4b4 100644
--- a/monkey/edits.py
+++ b/monkey/edits.py
@@ -8,13 +8,13 @@ from .graph import Node
from prolog.util import normalized, rename_vars, stringify, tokenize
from .util import get_line, avg, logistic
-# A line edit is a contiguous sequences of actions within a single line. This
-# function takes a sequence of actions and builds a directed acyclic graph
-# where each edit represents one line edit and each node represents a version
-# of some line. The function returns a list of nodes (first element is the
-# root), and sets of submissions (program versions tested by the user) and
-# queries in this attempt.
-def edit_graph(actions, debug=False):
+# Parse the sequence of actions in [trace] and return a directed acyclic graph
+# representing development history. Each node represents a particular version
+# of some line, and each edge represents a "line edit" (contiguous sequence of
+# inserts/removes within a single line).
+# Return a list of nodes (first element is the root), and sets of submissions
+# (program versions tested by the user) and queries in this attempt.
+def trace_graph(trace, debug=False):
# Return values.
nodes = [Node([0, 0, ()])] # Node data: rank (Y), line no. (X), and tokens.
submissions = set() # Program versions at 'test' actions.
@@ -26,8 +26,15 @@ def edit_graph(actions, debug=False):
code_next = '' # Program code after applying the current action.
done = False # Set to True on first correct version.
- # Ensure there is a separate action for each inserted/removed character.
- expand(actions)
+ # Parse trace actions and ensure there is a separate action for each
+ # inserted/removed character.
+ try:
+ actions = parse(trace)
+ expand(actions)
+ except:
+ # Only a few traces fail to parse, so just skip them.
+ actions = []
+
for action_id, action in enumerate(actions):
code = code_next
code_next = action.apply(code)
@@ -164,12 +171,7 @@ def get_edits_from_traces(traces):
n_all = collections.Counter()
for trace in traces:
- try:
- actions = parse(trace)
- except:
- # Only a few traces fail to parse, so just ignore them.
- continue
- nodes, trace_submissions, trace_queries = edit_graph(actions)
+ nodes, trace_submissions, trace_queries = trace_graph(trace)
# Update the submissions/queries counters (use normalized variables).
for submission in trace_submissions:
@@ -190,7 +192,7 @@ def get_edits_from_traces(traces):
end = normalized(path[i], var_names)
# Disallow edits that insert a whole rule (a → … :- …).
- # TODO improve edit_graph to handle this.
+ # TODO improve trace_graph to handle this.
if 'FROM' in [t.type for t in end[:-1]]:
continue