You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
818 B
29 lines
818 B
9 months ago
|
from cppy.cp_util import *
|
||
|
|
||
|
def extract_words(obj, path_to_file):
|
||
9 months ago
|
obj['data'] = extract_file_words(path_to_file)
|
||
9 months ago
|
|
||
|
def increment_count(obj, w):
|
||
|
obj['freqs'][w] = 1 if w not in obj['freqs'] else obj['freqs'][w]+1
|
||
|
|
||
|
data_storage_obj = {
|
||
|
'data' : [],
|
||
|
'init' : lambda path_to_file : extract_words(data_storage_obj, path_to_file),
|
||
|
'words' : lambda : data_storage_obj['data']
|
||
|
}
|
||
|
|
||
|
word_freqs_obj = {
|
||
|
'freqs' : {},
|
||
|
'increment_count' : lambda w : increment_count(word_freqs_obj, w),
|
||
|
'sorted' : lambda : sort_dict(word_freqs_obj['freqs'])
|
||
|
}
|
||
|
|
||
|
|
||
|
if __name__ == '__main__':
|
||
8 months ago
|
data_storage_obj['init']( testfilepath )
|
||
9 months ago
|
|
||
8 months ago
|
for word in data_storage_obj['words']():
|
||
|
word_freqs_obj['increment_count'](word)
|
||
9 months ago
|
|
||
|
word_freqs = word_freqs_obj['sorted']()
|
||
8 months ago
|
print_word_freqs(word_freqs)
|