美文网首页macOS/iOS自动化指南
利用auomator从文章中提取单词列表

利用auomator从文章中提取单词列表

作者: 鸭梨山大哎 | 来源:发表于2017-02-15 19:26 被阅读35次

前提是你安装好了python3 以及nltk这个库。(自行百度)
打开automator,新建app,

Paste_Image.png

Py文件内容,把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库非常麻烦,要有耐心。

没耐心的去这个网站、http://tools.eflclub.me/VocabularyAnalyzer

相关文章

网友评论

    本文标题:利用auomator从文章中提取单词列表

    本文链接:https://www.haomeiwen.com/subject/hnoqwttx.html