forked from p46318075/CodePattern
				
			
							parent
							
								
									a3bc46dae3
								
							
						
					
					
						commit
						9d74a5c184
					
				| @ -1,27 +0,0 @@ | ||||
| from cppy.cp_util import * | ||||
| 
 | ||||
| 
 | ||||
| # 框架类 | ||||
| class TFFlowcls: | ||||
|     def __init__(self, v): | ||||
|         self._value = v | ||||
| 
 | ||||
|     def bind(self, func): | ||||
|         self._value = func(self._value) | ||||
|         return self | ||||
| 
 | ||||
|     def over(self): | ||||
|         print(self._value) | ||||
| 
 | ||||
| 
 | ||||
| def top_freqs(word_freqs): | ||||
|     top10 = "\n".join(f"{word} - {count}" for word, count in word_freqs[:10]) | ||||
|     return top10 | ||||
| 
 | ||||
| if __name__ == "__main__": | ||||
|     TFFlowcls( testfilepath )\ | ||||
|     .bind(extract_file_words)\ | ||||
|     .bind(get_frequencies)\ | ||||
|     .bind(sort_dict)\ | ||||
|     .bind(top_freqs)\ | ||||
|     .over() | ||||
| @ -1,59 +0,0 @@ | ||||
| from cppy.cp_util import * | ||||
| 
 | ||||
| # | ||||
| # 框架类 | ||||
| # | ||||
| class TFFlowcls: | ||||
|     def __init__(self, func): | ||||
|         self._funcs = [func] | ||||
| 
 | ||||
|     def bind(self, func): | ||||
|         self._funcs.append(func) | ||||
|         return self | ||||
|      | ||||
|     def execute(self):      | ||||
|         def call_if_possible(obj):   | ||||
|             """Call the object if it's callable, otherwise return it as is."""   | ||||
|             return obj() if hasattr(obj, '__call__')  else obj   | ||||
|      | ||||
|         # Initialize the value to a no-op lambda function   | ||||
|         value = lambda: None               | ||||
|         for func in self._funcs:               | ||||
|             value = call_if_possible(func(value))                       | ||||
| 
 | ||||
| # | ||||
| # 工具函数 | ||||
| # | ||||
| 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(): | ||||
|         return print_word_freqs( word_freqs ) | ||||
|     return _f | ||||
| 
 | ||||
| 
 | ||||
| if __name__ == "__main__": | ||||
|     TFFlowcls(get_input)\ | ||||
|     .bind(extractwords)\ | ||||
|     .bind(frequencies)\ | ||||
|     .bind(sort)\ | ||||
|     .bind(top10_freqs)\ | ||||
|     .execute() | ||||
					Loading…
					
					
				
		Reference in new issue