나는 포르투갈어로 nltk와 함께 일하고 있습니다.
그것은 내 텍스트입니다.
import numpy as np
from nltk.corpus import machado, mac_morpho, floresta, genesis
from nltk.text import Text
ptext1 = Text(machado.words('romance/marm05.txt'), name="Memórias Póstumas de Brás Cubas (1881)")
ptext2 = Text(machado.words('romance/marm08.txt'), name="Dom Casmurro (1899)")
ptext3 = Text(genesis.words('portuguese.txt'), name="Gênesis")
ptext4 = Text(mac_morpho.words('mu94se01.txt'), name="Folha de Sao Paulo (1994)")
예를 들어 ptext4를 문장으로 나누고 단어로 나누고 싶습니다.
sentencas = nltk.sent_tokenize(ptext4)
palavras = nltk.word_tokenize(ptext4)
그러나 작동하지 않습니다. 오류는 예상되는 문자열 또는 바이트와 같은 객체입니다.
나는 이것을 시도했다 :
sentencas = [row for row in nltk.sent_tokenize(row)]
그러나 결과는 기대치가 아닙니다.
[In]sentencas
[Out] ['Fujimori']
내가 뭘 할 수 있니? 나는 그것에 새로운입니다.
machado
말뭉치 의 단어 목록 만 원하면 .words()
함수를 사용하십시오 .
>>> from nltk.corpus import machado
>>> machado.words()
그러나 원시 텍스트를 처리하려면
>>> text = machado.raw('romance/marm08.txt')
>>> print(text)
이 관용구 사용
>>> from nltk import word_tokenize, sent_tokenize
>>> text = machado.raw('romance/marm08.txt')
>>> tokenized_text = [word_tokenize(sent) for sent in sent_tokenize(text)]
그리고 반복 관통 tokenized_text
, 인 A는 list(list(str))
이 작업을 수행 :
>>> for sent in tokenize_text:
... for word in sent:
... print(word)
... break
...
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다