【发布时间】:2015-04-13 05:13:38
【问题描述】:
是否可以使用 nltk 将跑步、帮助、烹饪、发现和快乐等词更改为运行、帮助、烹饪、寻找和快乐?
【问题讨论】:
-
我在 whoosh 中使用了词干过滤器(在pypi.python.org/pypi/Whoosh/2.6.0 上查看更多信息)
是否可以使用 nltk 将跑步、帮助、烹饪、发现和快乐等词更改为运行、帮助、烹饪、寻找和快乐?
【问题讨论】:
nltk 中实现了一些词干提取算法。看起来Lancaster 词干算法对你有用。
>>> from nltk.stem.lancaster import LancasterStemmer
>>> st = LancasterStemmer()
>>> st.stem('happily')
'happy'
>>> st.stem('cooks')
'cook'
>>> st.stem('helping')
'help'
>>> st.stem('running')
'run'
>>> st.stem('finds')
'find'
【讨论】:
>>> from nltk.stem import WordNetLemmatizer
>>> wnl = WordNetLemmatizer()
>>> ls = ['running', 'helping', 'cooks', 'finds']
>>> [wnl.lemmatize(i) for i in ls]
['running', 'helping', u'cook', u'find']
>>> ls = [('running', 'v'), ('helping', 'v'), ('cooks', 'v'), ('finds','v')]
>>> [wnl.lemmatize(word, pos) for word, pos in ls]
[u'run', u'help', u'cook', u'find']
>>> ls = [('running', 'n'), ('helping', 'n'), ('cooks', 'n'), ('finds','n')]
>>> [wnl.lemmatize(word, pos) for word, pos in ls]
['running', 'helping', u'cook', u'find']
【讨论】: