【问题标题】:Is there a way to correctly remove the tense or plural from a word?有没有办法从单词中正确删除时态或复数?
【发布时间】:2015-04-13 05:13:38
【问题描述】:

是否可以使用 nltk 将跑步、帮助、烹饪、发现和快乐等词更改为运行、帮助、烹饪、寻找和快乐?

【问题讨论】:

标签: python nltk


【解决方案1】:

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'

【讨论】:

    【解决方案2】:
    >>> 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']
    

    见Porter Stemming of fried

    【讨论】:

      猜你喜欢
      • 2019-07-08
      • 1970-01-01
      • 2022-01-17
      • 2020-01-13
      • 2011-03-24
      • 1970-01-01
      • 2018-09-06
      • 2012-05-14
      • 1970-01-01
      相关资源
      最近更新 更多