この出力は予期しないものです。 In
は、PorterStemmerの出力から大文字のIn
を返します。
>>> from nltk.stem import PorterStemmer
>>> porter = PorterStemmer()
>>> porter.stem('In')
'In'
ステミングについては、正規化の一部として最初に小文字に変換することになっているのではないでしょうか。
Oh
を使用した大文字の出力の別の例
>>> from nltk.stem import PorterStemmer
>>> porter = PorterStemmer()
>>> porter.stem('Oh')
'Oh'
もともとは、州の略語のように、単語の長さが2未満の場合でも、元の略語の形式を維持したいからだと思います。
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]
いいですね! 私はそれに取り組みます。