From 4d19b772a98e0cdc85c44dd04a98bd863aa04c34 Mon Sep 17 00:00:00 2001 From: "Benedict J. Brown" Date: Tue, 29 Oct 2019 09:39:17 -0400 Subject: [PATCH 1/3] added nocomments and verbatim passes --- compare50/passes.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/compare50/passes.py b/compare50/passes.py index f2a2139..55af8da 100644 --- a/compare50/passes.py +++ b/compare50/passes.py @@ -24,6 +24,16 @@ class exact(Pass): preprocessors.strip_whitespace] comparator = comparators.Winnowing(k=25, t=35) +class nocomments(Pass): + """Removes comments, but keeps whitespace, then uses the winnowing algorithm to compare submissions""" + preprocessors = [ preprocessors.split_on_whitespace, preprocessors.strip_comments ] + comparator = comparators.Winnowing(k=25, t=35) + +class verbatim(Pass): + """Removes nothing, not even whitespaces, then uses the winnowing algorithm to compare submissions""" + preprocessors = [ ] + comparator = comparators.Winnowing(k=25, t=35) + class misspellings(Pass): """Compares comments for identically misspelled English words.""" From e6b692fbbf5e6f8dfefddb009eeda2cfabb49be4 Mon Sep 17 00:00:00 2001 From: Chad Sharp Date: Mon, 11 Nov 2019 21:12:48 -0500 Subject: [PATCH 2/3] Added notion of 'default' passes --- compare50/__main__.py | 5 +++-- compare50/_data.py | 3 +++ compare50/passes.py | 25 +++++++++++++------------ 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/compare50/__main__.py b/compare50/__main__.py index 7061159..b540dd4 100644 --- a/compare50/__main__.py +++ b/compare50/__main__.py @@ -117,7 +117,7 @@ def __init__(self, option_strings, dest=argparse.SUPPRESS, default=argparse.SUPP def __call__(self, parser, namespace, values, option_string=None): indentation = " " * 4 for pass_ in _data.Pass._get_all(): - print(str(pass_.__name__)) + print(str(pass_.__name__), f"(default: {'ON' if pass_.default else 'OFF'})") for line in textwrap.wrap(pass_.__doc__ or "No description provided", 80 - len(indentation)): print("{}{}".format(indentation, line)) parser.exit() @@ -225,7 +225,8 @@ def main(): parser.add_argument("-p", "--passes", dest="passes", nargs="+", - default=[pass_.__name__ for pass_ in _data.Pass._get_all()], + default=[pass_.__name__ for pass_ in _data.Pass._get_all() + if pass_.default], help="Specify which passes to use. compare50 ranks only by the first pass, but will render views for every pass.") parser.add_argument("-i", "--include", callback=submission_factory.include, diff --git a/compare50/_data.py b/compare50/_data.py index f96bd16..9f50b4e 100644 --- a/compare50/_data.py +++ b/compare50/_data.py @@ -43,6 +43,9 @@ class Pass(metaclass=_PassRegistry): """ __register = False + # Whether or not the pass should be enabled by default + default = False + @abc.abstractmethod def preprocessors(self): pass diff --git a/compare50/passes.py b/compare50/passes.py index 55af8da..5c23cff 100644 --- a/compare50/passes.py +++ b/compare50/passes.py @@ -8,7 +8,7 @@ class structure(Pass): """Compares code structure by removing whitespace and comments; normalizing variable names, string literals, and numeric literals; and then running the winnowing algorithm.""" - + default = True preprocessors = [preprocessors.strip_whitespace, preprocessors.strip_comments, preprocessors.normalize_identifiers, @@ -20,26 +20,27 @@ class structure(Pass): class exact(Pass): """Removes all whitespace, then uses the winnowing algorithm to compare submissions.""" + default = True preprocessors = [preprocessors.split_on_whitespace, preprocessors.strip_whitespace] comparator = comparators.Winnowing(k=25, t=35) -class nocomments(Pass): - """Removes comments, but keeps whitespace, then uses the winnowing algorithm to compare submissions""" - preprocessors = [ preprocessors.split_on_whitespace, preprocessors.strip_comments ] - comparator = comparators.Winnowing(k=25, t=35) - -class verbatim(Pass): - """Removes nothing, not even whitespaces, then uses the winnowing algorithm to compare submissions""" - preprocessors = [ ] - comparator = comparators.Winnowing(k=25, t=35) - class misspellings(Pass): """Compares comments for identically misspelled English words.""" - + default = True preprocessors = [preprocessors.comments, preprocessors.normalize_case, preprocessors.words] comparator = comparators.Misspellings(resource_filename("compare50.comparators", "english_dictionary.txt")) + +class nocomments(Pass): + """Removes comments, but keeps whitespace, then uses the winnowing algorithm to compare submissions""" + preprocessors = [preprocessors.split_on_whitespace, preprocessors.strip_comments] + comparator = comparators.Winnowing(k=25, t=35) + +class verbatim(Pass): + """Removes nothing, not even whitespace, then uses the winnowing algorithm to compare submissions""" + preprocessors = [] + comparator = comparators.Winnowing(k=25, t=35) From 0a3a5155993347d933da7ea3e6142aaa696e221e Mon Sep 17 00:00:00 2001 From: jelleas Date: Thu, 30 Apr 2020 13:57:58 +0200 Subject: [PATCH 3/3] remove comments, then split on whitespace --- compare50/passes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compare50/passes.py b/compare50/passes.py index 5c23cff..a9cf716 100644 --- a/compare50/passes.py +++ b/compare50/passes.py @@ -37,7 +37,7 @@ class misspellings(Pass): class nocomments(Pass): """Removes comments, but keeps whitespace, then uses the winnowing algorithm to compare submissions""" - preprocessors = [preprocessors.split_on_whitespace, preprocessors.strip_comments] + preprocessors = [preprocessors.strip_comments, preprocessors.split_on_whitespace] comparator = comparators.Winnowing(k=25, t=35) class verbatim(Pass):