From 88606f2bce812ba30301e5e94f477c2820c18857 Mon Sep 17 00:00:00 2001 From: zj3D Date: Fri, 22 Mar 2024 15:48:53 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E8=AE=A2=2011?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../5 插件/plugins-src/frequencies1.py | 2 +- .../5 插件/plugins-src/frequencies2.py | 4 ++-- .../5 插件/plugins-src/words1.py | 14 -------------- .../5 插件/plugins-src/words2.py | 8 -------- .../1 松耦合/5 插件/plugins/words1.pyc | Bin 664 -> 0 bytes .../5 插件/plugins/words2.cpython-38.pyc | Bin 585 -> 0 bytes 15 工程化/1 松耦合/5 插件/tf-20.py | 18 +++++++++--------- 7 files changed, 12 insertions(+), 34 deletions(-) delete mode 100644 15 工程化/1 松耦合/5 插件/plugins-src/words1.py delete mode 100644 15 工程化/1 松耦合/5 插件/plugins-src/words2.py delete mode 100644 15 工程化/1 松耦合/5 插件/plugins/words1.pyc delete mode 100644 15 工程化/1 松耦合/5 插件/plugins/words2.cpython-38.pyc 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 cd94afc09ae3d4671369b773e931895e0d80381e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 664 zcmY*X&2G~`5T04D9XG@kYJ2Drj^@XL15yuB#G&U(P@u@PvW#~VBHY;QZWIzZr&aj26>t=z#d{9=pZMf$k$R;16&V8!0Soq(ecN7Q zgDYIalAXX4cm~hmH5j(?gtx|}*LW)~c*E9g<*#8CP#!m(3-|(`V2HvO!DZO+L%47R zI!6nCYK9LFh(ahQMJ2|Q(IR+rdXk;pzs5T^NVz#V>8>NSPi91<&Tcz8pW%H+@dkge z5BwOeK)C^8W?Ayc;_M33t~OPj%_=2ydv|>+Ic=lINj6wSHO6q_V!Q%dttL zku;fO)3%TOv{&cmU1q9m=qhlShT5o1_*F___7y z9vQ%G+`%sHc>z;<6vsZ1nQP_dvjO4IqSIbc*Yl*Pv#A-EZQ2IjZExeXJ;MHZC8nhu MxG$nzk9`c;A9^vL%m4rY 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 d0d96eafad0d48a856e3a3ec270f8ca941ea44e1..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 585 zcmZWmv2GMG5S{UQ_ckFXkZ4lSP;Qj0P((p-I#E!k2{eXiwOad*70&Hq`*hr~S0xfj zfdqeWSLT;oAyM%QRE!r9f*5I@{p9g`Gxn?Da2F^JzI;=N0N(?-8;r5!>F7Xty_y^s9lMFo`R3v>HL2^JDQQD^j4mK#!v5sV9^qFm< zEo}G}wrq_qzJP1^1QV28#+PY_FW@4`Cnu|&*X7ab?Bns_dKJ&zJ2@9-;o&rjh7OsLD4XZaJ4iyIU>)-~;-G1B%&Kkwyl zdUl+*OTRnPwRKf<-j2gaHX%rWK?Vq?7<%+&KAL*tlwH?#u&y6hc%qTyY)H7LX z?RnFxnde58(#N`4C?keb<%-(|GA8!g(!DKQQ%q{DMEtie6Z}m|;D`S>hk5$G03Tt3 z=05Q(_K{s$6aL;O)){&*u~)V2GOyZV?rPna^#k95UOgS1H*&7kIQ*#%>id|oU!Bl~ A*#H0l 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