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.
35 lines
1.1 KiB
35 lines
1.1 KiB
9 months ago
|
import cppy.cp_util as util
|
||
|
|
||
|
##########################################
|
||
|
# 工具类
|
||
|
##########################################
|
||
|
class wordsTaskHandler:
|
||
|
def handle(self,path_to_file):
|
||
|
return util.extract_file_words(path_to_file)
|
||
|
|
||
|
class frequenciesTaskHandler:
|
||
|
def handle(self,word_list):
|
||
|
return util.get_frequencies(word_list)
|
||
|
|
||
|
class sortTaskHandler:
|
||
|
def handle(self,word_freq):
|
||
|
return util.sort_dict(word_freq)
|
||
|
|
||
|
##########################################
|
||
|
# 应用框架
|
||
|
##########################################
|
||
|
def handle_task(task_type,*args):
|
||
8 months ago
|
handler_class_name = f"{task_type}TaskHandler" # 构建处理器类名
|
||
|
|
||
9 months ago
|
handler_class = globals().get(handler_class_name)
|
||
|
if handler_class:
|
||
|
handler = handler_class() # 实例化处理器类
|
||
|
return handler.handle(*args) # 调用处理方法
|
||
|
else:
|
||
8 months ago
|
print(f"No found for task type: {task_type}")
|
||
9 months ago
|
|
||
|
|
||
8 months ago
|
word_list = handle_task("words",util.testfilepath)
|
||
|
word_freq = handle_task("frequencies",word_list)
|
||
|
word_sort = handle_task("sort",word_freq)
|
||
|
util.print_word_freqs(word_sort)
|