【问题标题】:Convert String 'shorter' to 'short' using Python nltk stem package使用 Python nltk stem 包将字符串“更短”转换为“短”
【发布时间】:2014-06-24 22:47:07
【问题描述】:

我正在尝试从 python 中的字符串中提取单词 tallershorter 的词干。

我做了以下事情:

>>> from nltk.stem.porter import *
>>> print(stemmer.stem('shorter'))
shorter
>>> print(stemmer.stem('taller'))
taller

由于某种原因,我没有看到 tallshort 这两个词。任何人都知道如何解决这个问题,或者可能指导替代解决方案?

【问题讨论】:

    标签: python nltk stemming


    【解决方案1】:

    有一些词干分析器。这是一个:

    >>> from nltk.stem.lancaster import LancasterStemmer
    >>> stemmer = LancasterStemmer()
    >>> stemmer.stem('shorter')
    'short'
    

    【讨论】:

    • @wim 感谢您的洞察力。但请注意更高 --> tal .
    • 嗯 .. 抱歉,这不是我的领域 - 也许你必须训练他们?
    • @wim 我不确定这将如何工作。无论如何,谢谢。
    【解决方案2】:
    >>> from nltk import stem
    >>> s = 'short'; t = 'tall'
    >>> porter = stem.porter.PorterStemmer()
    >>> lancaster = stem.lancaster.LancasterStemmer()
    >>> snowball = stem.snowball.EnglishStemmer()
    >>> porter.stem(s)
    u'short'
    >>> porter.stem(t)
    u'tall'
    >>> lancaster.stem(s)
    'short'
    >>> lancaster.stem(t)
    'tal'
    >>> snowball.stem(s)
    u'short'
    >>> snowball.stem(t)
    u'tall'
    

    【讨论】:

      猜你喜欢
      • 2014-05-20
      • 1970-01-01
      • 2023-03-28
      • 2013-03-26
      • 2016-02-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-09
      相关资源
      最近更新 更多