2017-09-30 1 views
0

대화 형이 아닌 텍스트를 문장으로 토큰화할 수 있지만 문장에 인용 부호를 추가하면 NLTK 토크 나이저가 올바르게 분할되지 않습니다. 예를 들어,이는 예상대로 작동합니다 :NLTK 문장으로 대화 상자로 텍스트 토큰 화

import nltk.data 
tokenizer = nltk.data.load('tokenizers/punkt/english.pickle') 
text1 = 'Is this one sentence? This is separate. This is a third he said.' 
tokenizer.tokenize(text1) 

이 세 가지 서로 다른 문장의 결과리스트에 : 나는 대화에 그것을 만들 경우

['Is this one sentence?', 'This is separate.', 'This is a third he said.'] 

그러나, 동일한 프로세스가 작동하지 않습니다.

text2 = '“Is this one sentence?” “This is separate.” “This is a third” he said.' 
tokenizer.tokenize(text2) 

이 하나의 문장으로 반환

['“Is this one sentence?” “This is separate.” “This is a third” he said.'] 

가 어떻게이 경우 작업 토크 나이 NLTK를 만들 수 있습니까?

답변

1

tokenizer는 지시 된 따옴표로 무엇을해야할지 모른다. 정규 ASCII 따옴표로 바꾸면 예제가 올바르게 작동합니다.

>>> text3 = re.sub('[“”]', '"', text2) 
>>> nltk.sent_tokenize(text3) 
['"Is this one sentence?"', '"This is separate."', '"This is a third" he said.']