From 9c474d619f008f38ccf54dc1e6fe49b43a1b8432 Mon Sep 17 00:00:00 2001 From: Crista Lopes Date: Thu, 28 Nov 2013 19:31:18 -0800 Subject: [PATCH] Simplified the quarantine style a little bit by merging some of the functions. --- 24-quarantine/README.md | 2 +- 24-quarantine/tf-24.py | 22 ++++------------------ 2 files changed, 5 insertions(+), 19 deletions(-) diff --git a/24-quarantine/README.md b/24-quarantine/README.md index 2f6eec8..7bd003a 100644 --- a/24-quarantine/README.md +++ b/24-quarantine/README.md @@ -3,7 +3,7 @@ Style #24 Constraints: -- Core program functions have no side effects of any kind, inlcuding IO +- Core program functions have no side effects of any kind, including IO - All IO actions must be contained in computation sequences that are clearly separated from the pure functions diff --git a/24-quarantine/tf-24.py b/24-quarantine/tf-24.py index 70624f4..ac4a427 100644 --- a/24-quarantine/tf-24.py +++ b/24-quarantine/tf-24.py @@ -26,27 +26,13 @@ def get_input(arg): return sys.argv[1] return _f -def read_file(path_to_file): +def extract_words(path_to_file): def _f(): with open(path_to_file) as f: data = f.read() - return data - return _f - -def filter_chars(str_data): - def _f(): pattern = re.compile('[\W_]+') - return pattern.sub(' ', str_data) - return _f - -def normalize(str_data): - def _f(): - return str_data.lower() - return _f - -def scan(str_data): - def _f(): - return str_data.split() + word_list = pattern.sub(' ', data).lower().split() + return word_list return _f def remove_stop_words(word_list): @@ -86,6 +72,6 @@ def top25_freqs(word_freqs): # The main function # quarantine = TFQuarantine() -quarantine.bind(get_input).bind(read_file).bind(filter_chars).bind(normalize).bind(scan).bind(remove_stop_words).bind(frequencies).bind(sort).bind(top25_freqs) +quarantine.bind(get_input).bind(extract_words).bind(remove_stop_words).bind(frequencies).bind(sort).bind(top25_freqs) quarantine.execute()