【发布时间】:2018-03-11 23:38:36
【问题描述】:
我能够将非对话文本标记为句子,但是当我在句子中添加引号时,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 标记器工作?
【问题讨论】: