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.
|
|
|
from collections import Counter
|
|
|
|
from cppy.cp_util import *
|
|
|
|
|
|
|
|
class AcceptTypes:
|
|
|
|
def __init__(self, *args):
|
|
|
|
self._args = args
|
|
|
|
|
|
|
|
def __call__(self, f):
|
|
|
|
def wrapped_f(*args, **kwargs):
|
|
|
|
for i, arg_type in enumerate(self._args):
|
|
|
|
if not isinstance(args[i], arg_type):
|
|
|
|
raise TypeError(f"Argument {i} expected {arg_type}, got {type(args[i])}")
|
|
|
|
return f(*args, **kwargs)
|
|
|
|
return wrapped_f
|
|
|
|
|
|
|
|
@AcceptTypes(str)
|
|
|
|
def extract_words_(path_to_file):
|
|
|
|
return extract_file_words(path_to_file)
|
|
|
|
|
|
|
|
@AcceptTypes(list)
|
|
|
|
def frequencies_(word_list):
|
|
|
|
return Counter(word_list)
|
|
|
|
|
|
|
|
@AcceptTypes(Counter)
|
|
|
|
def sort_(word_freq):
|
|
|
|
return word_freq.most_common()
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
word_freqs = sort_(frequencies_(extract_words_( testfilepath )))
|
|
|
|
print_word_freqs(word_freqs)
|