From 1c1b8f683ee2025497e2733eb0d8bc1e54035487 Mon Sep 17 00:00:00 2001 From: Timotej Lazar Date: Sat, 7 Feb 2015 19:47:57 +0100 Subject: Remove all trailing punctuation from lines MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Remove trailing sequences of COMMAs and PERIODs when extracting edits from a trace. This is because subgoal order is rarely important in Prolog, and we don't care if the edit happened on the last line or not. This means that we treat for example "conc(A,B)," → "conc(A,B,C)." the same as "conc(A,B)" → "conc(A,B,C)". --- monkey/edits.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'monkey') diff --git a/monkey/edits.py b/monkey/edits.py index ad595b6..a920bf5 100644 --- a/monkey/edits.py +++ b/monkey/edits.py @@ -146,12 +146,14 @@ def get_paths(root, path=None, done=None): # edits. Return a dictionary of edits and their frequencies, and also # submissions and queries in [traces]. def get_edits_from_traces(traces): - # Helper function to remove trailing punctuation from lines. This is a - # rather ugly performance-boosting hack. + # Helper function to remove trailing punctuation from lines. def remove_punct(line): - if line and line[-1].type in ('COMMA', 'PERIOD', 'SEMI', 'FROM'): - return line[:-1] - return line + i = len(line) + while i > 0: + if line[i-1].type not in ('COMMA', 'PERIOD', 'SEMI'): + break + i -= 1 + return line[:i] # Return values: counts for observed edits, lines, submissions and queries. edits = collections.Counter() -- cgit v1.2.1