|
|
@ -22,7 +22,7 @@ class WordFrequencyController():
|
|
|
|
#定义具体的享元类
|
|
|
|
#定义具体的享元类
|
|
|
|
class ConcreteWordFrequencyController(WordFrequencyController):
|
|
|
|
class ConcreteWordFrequencyController(WordFrequencyController):
|
|
|
|
def __init__(self, controllertype,filepath):
|
|
|
|
def __init__(self, controllertype,filepath):
|
|
|
|
self.word_list = extract_words(filepath)
|
|
|
|
self.word_list = extract_file_words(filepath)
|
|
|
|
self.word_freq = get_frequencies(self.word_list)
|
|
|
|
self.word_freq = get_frequencies(self.word_list)
|
|
|
|
self.word_freq = sort_dict(self.word_freq)
|
|
|
|
self.word_freq = sort_dict(self.word_freq)
|
|
|
|
def print_word_freqs(self, number):
|
|
|
|
def print_word_freqs(self, number):
|
|
|
@ -51,7 +51,7 @@ if __name__ == "__main__":
|
|
|
|
factory = WordFrequencyControllerFactory()
|
|
|
|
factory = WordFrequencyControllerFactory()
|
|
|
|
while True:
|
|
|
|
while True:
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
number = input("请输入需要显示词频前几的单词")
|
|
|
|
number = input("请输入需要显示词频前几的单词: ")
|
|
|
|
process_command(factory, number)
|
|
|
|
process_command(factory, number)
|
|
|
|
except EOFError:
|
|
|
|
except EOFError:
|
|
|
|
break
|
|
|
|
break
|