제발, 제발 도와주세요. NLTK를 사용하여 분석하려는 텍스트 파일로 채워진 폴더가 있습니다. 어떻게 그것을 코퍼스로 가져 와서 NLTK 명령을 실행합니까? 나는 아래의 코드를 함께 넣어했지만 그것은 나에게 오류를주고 :NLTK 자료 가져 오기 및 사용
raise error, v # invalid expression
sre_constants.error: nothing to repeat
코드 :
import nltk
import re
from nltk.corpus.reader.plaintext import PlaintextCorpusReader
corpus_root = '/Users/jt/Documents/Python/CRspeeches'
speeches = PlaintextCorpusReader(corpus_root, '*.txt')
print "Finished importing corpus"
words = FreqDist()
for sentence in speeches.sents():
for word in sentence:
words.inc(word.lower())
print words["he"]
print words.freq("he")
우리에게 많은 것을주지는 않을 것입니다. 간단히 말해 ** 어디에서 ** 오류가 있습니까? 처음에는 오류 추적을 모두 포함시킨 다음 단계별로 프로그램을 진행하십시오. 당신의 코퍼스는'CRspeeches' 디렉토리에'.txt' 파일로 구성되어 있습니까? 'speeches'를 초기화 한 후에'print (speeches.fileids()) '를 사용하여 파일 목록을 얻으십니까? 'speeches.sents()'가 반환해야하는 문장을 _print_ 할 수 있습니까? – alexis