利用auomator從文章中提取單詞列表

前提是你安裝好了python3 以及nltk這個庫。(自行百度)
打開automator,新建app,

Paste_Image.png

Py文件內(nèi)容,把corpus_root='/Users/noneback/protoncorpus'改成你存放txt文本的位置。把要分析的txt文本存在這里即可。

#!/usr/bin/env python
# -*- coding:utf-8 -*-

from nltk.corpus import PlaintextCorpusReader
corpus_root='/Users/noneback/protoncorpus'
wordlists=PlaintextCorpusReader(corpus_root,'.*')

def getcb():
#從文本中提取單詞列表
       cb=[]
       for x in wordlists.fileids():
              if x.endswith('.txt'):
                     print (x)
                     cb.extend(wordlists.words(x))
       return cb

def nocfcb():
#去掉單詞列表中重復的單詞
       s=getcb()
       print (len(s))
       s1=set(s)
       s2=sorted([w for w in s1 if w.isalpha() and w.islower()])
       for x in s2:
              print (x)

if __name__=='__main__':
       nocfcb()

效果如圖

Paste_Image.png

ps:安裝nltk庫非常麻煩,要有耐心。

沒耐心的去這個網(wǎng)站、http://tools.eflclub.me/VocabularyAnalyzer

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容