5
document classification, as described in NLTK Chapter 6을하려고하는데 불용어 제거에 문제가 있습니다. 내가NLTK 스톱 워드 제거 문제
all_words = (w for w in all_words if w not in nltk.corpus.stopwords.words('english'))
를 추가 할 때 나는 그들이() 함수는 쓸모 .KEY 렌더링, 스톱 워드 코드는 'all_words'에 사용되는 객체의 유형을 변경 한 같은데요
Traceback (most recent call last):
File "fiction.py", line 8, in <module>
word_features = all_words.keys()[:100]
AttributeError: 'generator' object has no attribute 'keys'
를 반환합니다. 유형을 변경하지 않고 키 기능을 사용하기 전에 중지 단어를 제거하려면 어떻게해야합니까? 아래의 전체 코드 :
import nltk
from nltk.corpus import PlaintextCorpusReader
corpus_root = './nltk_data/corpora/fiction'
fiction = PlaintextCorpusReader(corpus_root, '.*')
all_words=nltk.FreqDist(w.lower() for w in fiction.words())
all_words = (w for w in all_words if w not in nltk.corpus.stopwords.words('english'))
word_features = all_words.keys()[:100]
def document_features(document): # [_document-classify-extractor]
document_words = set(document) # [_document-classify-set]
features = {}
for word in word_features:
features['contains(%s)' % word] = (word in document_words)
return features
print document_features(fiction.words('fic/11.txt'))
에서 상속됩니다. 고맙습니다! – user3128184