【发布时间】:2012-05-09 07:25:12
【问题描述】:
我需要一个好的 python 模块来在预处理阶段提取文本文档。
我找到了这个
http://pypi.python.org/pypi/PyStemmer/1.0.1
但我在提供的链接中找不到文档。
我有人知道在哪里可以找到文档或任何其他好的词干算法,请帮忙。
【问题讨论】:
标签: python module preprocessor nlp stemming
我需要一个好的 python 模块来在预处理阶段提取文本文档。
我找到了这个
http://pypi.python.org/pypi/PyStemmer/1.0.1
但我在提供的链接中找不到文档。
我有人知道在哪里可以找到文档或任何其他好的词干算法,请帮忙。
【问题讨论】:
标签: python module preprocessor nlp stemming
你可以试试NLTK
>>> from nltk import PorterStemmer
>>> PorterStemmer().stem('complications')
【讨论】:
Python 词干提取模块实现了各种词干提取算法,例如 Porter、Porter2、Paice-Husk 和 Lovins。 http://pypi.python.org/pypi/stemming/1.0
>> from stemming.porter2 import stem
>> stem("factionally")
faction
【讨论】:
这里讨论的所有这些词干分析器都是算法词干分析器,因此它们总是会产生意想不到的结果,例如
In [3]: from nltk.stem.porter import *
In [4]: stemmer = PorterStemmer()
In [5]: stemmer.stem('identified')
Out[5]: u'identifi'
In [6]: stemmer.stem('nonsensical')
Out[6]: u'nonsens'
要正确获取词根,需要一个基于字典的词干分析器,例如 Hunspell Stemmer。下面是 link 中的一个 python 实现。示例代码在这里
>>> import hunspell
>>> hobj = hunspell.HunSpell('/usr/share/myspell/en_US.dic', '/usr/share/myspell/en_US.aff')
>>> hobj.spell('spookie')
False
>>> hobj.suggest('spookie')
['spookier', 'spookiness', 'spooky', 'spook', 'spoonbill']
>>> hobj.spell('spooky')
True
>>> hobj.analyze('linked')
[' st:link fl:D']
>>> hobj.stem('linked')
['link']
【讨论】:
stem('nonsense') == stem('nonsensical') != stem('bananas')就可以了。
PyStemmer 是 Snowball 词干库的 Python 接口。
文档可以在这里找到: https://github.com/snowballstem/pystemmer/blob/master/docs/quickstart.txt https://github.com/snowballstem/pystemmer/blob/master/docs/quickstart_python3.txt
【讨论】:
用于主题建模的 gensim package 带有 Porter Stemmer 算法:
>>> from gensim import parsing
>>> gensim.parsing.stem_text("trying writing nonsense")
'try write nonsens'
PorterStemmer 是在gensim 中实现的唯一词干提取选项。
附注:我可以想象(无需进一步参考)大多数与文本挖掘相关的模块都有自己的实现,用于简单的预处理过程,例如 Porter 的词干提取、空格删除和停用词删除。
【讨论】: