kai*_*rav 18 python preprocessor nlp module stemming
我需要一个好的python模块来在预处理阶段阻止文本文档.
我找到了这个
http://pypi.python.org/pypi/PyStemmer/1.0.1
但我无法在提供的链接中找到文档.
我知道在哪里可以找到文档或任何其他良好的词干算法请帮忙.
dit*_*kin 32
您可能想尝试NLTK
>>> from nltk import PorterStemmer
>>> PorterStemmer().stem('complications')
Run Code Online (Sandbox Code Playgroud)
Python词干模块具有各种词干算法的实现,如Porter,Porter2,Paice-Husk和Lovins. http://pypi.python.org/pypi/stemming/1.0
>> from stemming.porter2 import stem
>> stem("factionally")
faction
Run Code Online (Sandbox Code Playgroud)
这里讨论的所有这些词干分析器都是算法词干分析器,因此它们总能产生意想不到的结果,例如
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'
Run Code Online (Sandbox Code Playgroud)
要正确获取根词,需要一个基于字典的词干提取器,如Hunspell Stemmer.Here是以下链接中的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']
Run Code Online (Sandbox Code Playgroud)