그래, 그 paulryan.txt 파일의 각 라인이 얼마나 긍정적인지 음수인지를 알려주는 프로그램을 만들려고합니다. opinion_lexicon을 사용하고 있는데 파일이 '_io.TextIOWrapper'입니다.Python .words 문제가 있습니까?
.words 대신 사용할 수있는 것이 있습니까?
기타 덜 중요한 문제 : 줄 단위로 토큰을 유지하면서 내 전체 paulryan.txt 파일을 소문자로 만드는 방법은 무엇입니까? opinion_lexicon에 소문자 단어 만 있기 때문에 전체를 소문자로 만들지 않으면 정확한 양수 또는 음수 점수를 얻지 못할 것이라고 생각합니다.
import nltk
from nltk.corpus import opinion_lexicon
from nltk.tokenize.simple import (LineTokenizer, line_tokenize)
poswords = set(opinion_lexicon.words("positive-words.txt"))
negwords = set(opinion_lexicon.words("negative-words.txt"))
f=open("paulryan.txt", "rU")
raw = f.read()
token= nltk.line_tokenize(raw)
print(token)
def finddemons():
for x in token:
y = token.words()
percpos = len([w for w in token if w in poswords ])/len(y)
percneg = len([w for w in token if w in negwords ])/len(y)
print(x, "pos:", round(percpos, 3), "neg:", round(percneg, 3))
finddemons()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 3, in finddemons
AttributeError: 'list' object has no attribute 'words'
당신이 NLTK와 'spacy' 인터페이스를 혼동하는 것 같습니다.)'nltk import word_tokenize; y = word_tokenize (토큰) ' – alvas
흠. 글쎄, 나는 그것을 시도했지만 모든 것을 하나의 큰 것으로 합쳤다. :/줄 단위로 구분하기 위해 필요하다. 줄 단위로 짹짹으로 가득 찬 텍스트 문서 – rlavalla