forked from p46318075/CodePattern
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.
31 lines
847 B
31 lines
847 B
from collections import Counter
|
|
from cppy.cp_util import *
|
|
|
|
class TypesCheck:
|
|
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" {i} expected {arg_type}, got {type(args[i])}")
|
|
return f(*args, **kwargs)
|
|
return wrapped_f
|
|
|
|
@TypesCheck(str)
|
|
def extract_words_(path_to_file):
|
|
return extract_file_words(path_to_file)
|
|
|
|
@TypesCheck(list)
|
|
def frequencies_(word_list):
|
|
return Counter(word_list)
|
|
|
|
@TypesCheck(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) |