此输出是意外的。 In
In
从 PorterStemmer 的输出中返回大写的
>>> from nltk.stem import PorterStemmer
>>> porter = PorterStemmer()
>>> porter.stem('In')
'In'
对于任何词干提取,我们不应该首先将它们转换为小写作为规范化的一部分吗?
另一个使用Oh
的大写输出示例
>>> from nltk.stem import PorterStemmer
>>> porter = PorterStemmer()
>>> porter.stem('Oh')
'Oh'
我想是因为原来它想在字长小于2的时候保持缩写的原始形式,就像states的缩写一样。
def stem(self, word):
stem = word.lower()
if self.mode == self.NLTK_EXTENSIONS and word in self.pool:
return self.pool[word]
if self.mode != self.ORIGINAL_ALGORITHM and len(word) <= 2:
# With this line, strings of length 1 or 2 don't go through
# the stemming process, although no mention is made of this
# in the published algorithm.
return word
stem = self._step1a(stem)
stem = self._step1b(stem)
stem = self._step1c(stem)
stem = self._step2(stem)
stem = self._step3(stem)
stem = self._step4(stem)
stem = self._step5a(stem)
stem = self._step5b(stem)
return stem
单词 'In' 和 'Oh' 都不在self.pool
和len(word)<=2
,这意味着它不满足这里的词干条件,所以它保持不变。
如果它没有被分配,我可以处理这个吗? 这是我第一次为项目做出贡献。
@PhanatosZou 可以随意进行更改并创建拉取请求。 需要修改的主要代码是:
if self.mode != self.ORIGINAL_ALGORITHM and len(word) <= 2:
# With this line, strings of length 1 or 2 don't go through
# the stemming process, although no mention is made of this
# in the published algorithm.
return stem
但是最好检查self.pool
所有键,如果它们是非大写的,那么也要对此进行更改:
if self.mode == self.NLTK_EXTENSIONS and word in self.pool:
return self.pool[stem]
听起来不错! 我会努力的。