diff --git a/15 工程化/1 松耦合/5 插件/plugins-src/frequencies1.py b/15 工程化/1 松耦合/5 插件/plugins-src/frequencies1.py index d7cb297..ba452f7 100644 --- a/15 工程化/1 松耦合/5 插件/plugins-src/frequencies1.py +++ b/15 工程化/1 松耦合/5 插件/plugins-src/frequencies1.py @@ -1,6 +1,6 @@ import operator -def top25(word_list): +def top_word(word_list): word_freqs = {} for w in word_list: if w in word_freqs: diff --git a/15 工程化/1 松耦合/5 插件/plugins-src/frequencies2.py b/15 工程化/1 松耦合/5 插件/plugins-src/frequencies2.py index 474f333..4457270 100644 --- a/15 工程化/1 松耦合/5 插件/plugins-src/frequencies2.py +++ b/15 工程化/1 松耦合/5 插件/plugins-src/frequencies2.py @@ -1,6 +1,6 @@ -import operator, collections +import collections -def top25(word_list): +def top_word(word_list): counts = collections.Counter(w for w in word_list) return counts.most_common(10) diff --git a/15 工程化/1 松耦合/5 插件/plugins-src/words1.py b/15 工程化/1 松耦合/5 插件/plugins-src/words1.py deleted file mode 100644 index b989cbb..0000000 --- a/15 工程化/1 松耦合/5 插件/plugins-src/words1.py +++ /dev/null @@ -1,14 +0,0 @@ -import sys, re, string -from cppy.cp_util import * - -def extract_words(path_to_file): - with open(path_to_file,encoding='utf-8') as f: - str_data = f.read() - pattern = re.compile('[\W_]+') - word_list = pattern.sub(' ', str_data).lower().split() - - - stop_words = get_stopwords() - - return [w for w in word_list if not w in stop_words] - diff --git a/15 工程化/1 松耦合/5 插件/plugins-src/words2.py b/15 工程化/1 松耦合/5 插件/plugins-src/words2.py deleted file mode 100644 index 46a49f5..0000000 --- a/15 工程化/1 松耦合/5 插件/plugins-src/words2.py +++ /dev/null @@ -1,8 +0,0 @@ -import sys, re, string -from cppy.cp_util import * - -def extract_words(path_to_file): - words = re.findall('[a-z]{2,}', open(path_to_file,encoding='utf-8').read().lower()) - stopwords = get_stopwords() - return [w for w in words if w not in stopwords] - diff --git a/15 工程化/1 松耦合/5 插件/plugins/words1.pyc b/15 工程化/1 松耦合/5 插件/plugins/words1.pyc deleted file mode 100644 index cd94afc..0000000 Binary files a/15 工程化/1 松耦合/5 插件/plugins/words1.pyc and /dev/null differ diff --git a/15 工程化/1 松耦合/5 插件/plugins/words2.cpython-38.pyc b/15 工程化/1 松耦合/5 插件/plugins/words2.cpython-38.pyc deleted file mode 100644 index d0d96ea..0000000 Binary files a/15 工程化/1 松耦合/5 插件/plugins/words2.cpython-38.pyc and /dev/null differ diff --git a/15 工程化/1 松耦合/5 插件/tf-20.py b/15 工程化/1 松耦合/5 插件/tf-20.py index 1dbcd28..cebe2d2 100644 --- a/15 工程化/1 松耦合/5 插件/tf-20.py +++ b/15 工程化/1 松耦合/5 插件/tf-20.py @@ -1,19 +1,19 @@ import configparser, importlib.machinery from cppy.cp_util import * - def load_plugins(): - config = configparser.ConfigParser() + config = configparser.ConfigParser() script_dir = os.path.dirname(os.path.abspath(__file__)) - os.chdir(script_dir) - config.read("config.ini") - words_plugin = config.get("Plugins", "words") + os.chdir(script_dir) + config.read("config.ini") frequencies_plugin = config.get("Plugins", "frequencies") - global tfwords, tffreqs - tfwords = importlib.machinery.SourcelessFileLoader('tfwords', words_plugin).load_module() - tffreqs = importlib.machinery.SourcelessFileLoader('tffreqs', frequencies_plugin).load_module() + + global get_frequencies + get_frequencies = importlib.machinery.SourcelessFileLoader('tffreqs', frequencies_plugin).load_module() + load_plugins() -word_freqs = tffreqs.top25(tfwords.extract_words( testfilepath )) +wordlist = extract_file_words( testfilepath ) +word_freqs = get_frequencies.top_word( wordlist ) print_word_freqs(word_freqs) \ No newline at end of file