0

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

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

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

为什么我得到两个不同的结果?它是否正确?

4

1 回答 1

3

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

没有标记化:

>>> 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']
于 2016-01-27T15:31:46.473 回答