Simplified the quarantine style a little bit by merging some of the functions.
This commit is contained in:
@@ -3,7 +3,7 @@ Style #24
|
|||||||
|
|
||||||
Constraints:
|
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
|
- All IO actions must be contained in computation sequences that are
|
||||||
clearly separated from the pure functions
|
clearly separated from the pure functions
|
||||||
|
|||||||
@@ -26,27 +26,13 @@ def get_input(arg):
|
|||||||
return sys.argv[1]
|
return sys.argv[1]
|
||||||
return _f
|
return _f
|
||||||
|
|
||||||
def read_file(path_to_file):
|
def extract_words(path_to_file):
|
||||||
def _f():
|
def _f():
|
||||||
with open(path_to_file) as f:
|
with open(path_to_file) as f:
|
||||||
data = f.read()
|
data = f.read()
|
||||||
return data
|
|
||||||
return _f
|
|
||||||
|
|
||||||
def filter_chars(str_data):
|
|
||||||
def _f():
|
|
||||||
pattern = re.compile('[\W_]+')
|
pattern = re.compile('[\W_]+')
|
||||||
return pattern.sub(' ', str_data)
|
word_list = pattern.sub(' ', data).lower().split()
|
||||||
return _f
|
return word_list
|
||||||
|
|
||||||
def normalize(str_data):
|
|
||||||
def _f():
|
|
||||||
return str_data.lower()
|
|
||||||
return _f
|
|
||||||
|
|
||||||
def scan(str_data):
|
|
||||||
def _f():
|
|
||||||
return str_data.split()
|
|
||||||
return _f
|
return _f
|
||||||
|
|
||||||
def remove_stop_words(word_list):
|
def remove_stop_words(word_list):
|
||||||
@@ -86,6 +72,6 @@ def top25_freqs(word_freqs):
|
|||||||
# The main function
|
# The main function
|
||||||
#
|
#
|
||||||
quarantine = TFQuarantine()
|
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()
|
quarantine.execute()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user