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.

59 lines
1.3 KiB

9 months ago
from cppy.cp_util import *
#
# 框架类
#
9 months ago
class TFFlowcls:
9 months ago
def __init__(self, func):
self._funcs = [func]
def bind(self, func):
self._funcs.append(func)
return self
9 months ago
def execute(self):
9 months ago
def call_if_possible(obj):
"""Call the object if it's callable, otherwise return it as is."""
9 months ago
return obj() if hasattr(obj, '__call__') else obj
9 months ago
# Initialize the value to a no-op lambda function
value = lambda: None
for func in self._funcs:
9 months ago
value = call_if_possible(func(value))
9 months ago
#
# 工具函数
#
def get_input(arg):
def _f():
return testfilepath
return _f
def extractwords(path_to_file):
def _f():
return extract_file_words(path_to_file)
return _f
def frequencies(word_list):
def _f():
return get_frequencies(word_list)
return _f
def sort(word_freq):
def _f():
return sort_dict(word_freq)
return _f
def top10_freqs(word_freqs):
def _f():
9 months ago
return print_word_freqs( word_freqs )
9 months ago
return _f
if __name__ == "__main__":
9 months ago
TFFlowcls(get_input)\
9 months ago
.bind(extractwords)\
.bind(frequencies)\
.bind(sort)\
.bind(top10_freqs)\
.execute()