無効な英語の単語や数字などを含む汚い文書があります。有効な英語の単語をすべて取得して、有効な英語の単語の総数に対する単語のリストの比率を計算したいだけです。
たとえば、私のドキュメントに次の文が含まれている場合:
sentence= ['eishgkej he might be a good person. I might consider this.']
数えたいだけ"he might be a good person. I might consider this"
で数えたい"might"
。
だから、私は2/10の答えを得ました。
以下のコードを使うことを考えています。ただし、行features[word] = 1
ではなく機能の数を変更する必要があります...
all_words = nltk.FreqDist(w.lower() for w in reader.words() if w.lower() not in english_sw)
def document_features(document):
document_words = set(document)
features = {}
for word in word_features:
if word in document_words:
features[word] = 1
else:
features[word]=0
return features