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.
29 lines
758 B
29 lines
758 B
from cppy.cp_util import *
|
|
|
|
class Flow:
|
|
def extract_file_words(self, filepath):
|
|
self.data = extract_file_words(filepath)
|
|
return self
|
|
|
|
def get_frequencies(self):
|
|
self.data = get_frequencies(self.data)
|
|
return self
|
|
|
|
def sort_dict(self):
|
|
self.data = sort_dict(self.data)
|
|
return self
|
|
|
|
def print_word_freqs(self, n):
|
|
print_word_freqs(self.data, n)
|
|
return self
|
|
|
|
|
|
# 顺序调用
|
|
Flow().extract_file_words(testfilepath).get_frequencies().sort_dict().print_word_freqs(10)
|
|
|
|
'''
|
|
连续方法调用,看起来比较舒服
|
|
但是需要假设:
|
|
- 每一个类方法返回 self :否则,没法连续
|
|
- 类方法默认不写第一个参数,数据都在 .data 里面
|
|
''' |