【问题标题】:What should be the outcome of stemming a word with apostrophe?用撇号词干的结果应该是什么?
【发布时间】:2016-01-27 23:31:46
【问题描述】:

我在 python 中使用nltk.stem.porter.PorterStemmer 来获取词干。

当我得到“women”和“women's”的词干时,我分别得到不同的结果:“women”和“women'”。出于我的目的,我需要两个词具有相同的词干。

在我的思路中,这两个词指的是同一个想法/概念,并且几乎是同一个词,经历了转变,所以它们应该有相同的词干。

为什么我会得到两个不同的结果?这是正确的吗?

【问题讨论】:

  • 我认为你应该首先标记你的文本删除所有标点符号。

标签: python nltk stemming stem


【解决方案1】:

在词形还原之前有必要对文本进行标记。

没有标记化:

>>> from nltk import word_tokenize
>>> from nltk.stem import WordNetLemmatizer
>>> wnl = WordNetLemmatizer()

>>> [wnl.lemmatize(i) for i in "the woman's going home".split()]
['the', "woman's", 'going', 'home']
>>> [wnl.lemmatize(i) for i in "the women's home is in London".split()]
['the', "women's", 'home', 'is', 'in', 'London']

使用标记化:

>>> [wnl.lemmatize(i) for i in word_tokenize("the woman's going home")]
['the', 'woman', "'s", 'going', 'home']
>>> [wnl.lemmatize(i) for i in word_tokenize("the women's home is in London")]
['the', u'woman', "'s", 'home', 'is', 'in', 'London']

【讨论】:

    猜你喜欢
    • 2012-07-20
    • 1970-01-01
    • 2010-11-30
    • 1970-01-01
    • 2016-02-20
    • 2010-12-05
    • 1970-01-01
    • 2014-07-25
    • 1970-01-01
    相关资源
    最近更新 更多