句子输入列表:
sentences = [
"""Well, I've tried to say "How Doth the Little Busy Bee," but it all came different!""",
"""Alice replied in a very melancholy voice. She continued, 'I'll try again.'"""
]
所需输出:
^{pr2}$有没有一种方法可以使用内置或第三方标记器提取带有nltk
的引文(可以用单引号和双引号出现)?在
我尝试过使用^{parens
值,但结果与预期相差甚远,例如:
In [1]: from nltk import SExprTokenizer
...:
...:
...: sentences = [
...: """Well, I've tried to say "How Doth the Little Busy Bee," but it all came different!""",
...: """Alice replied in a very melancholy voice. She continued, 'I'll try again.'"""
...: ]
...:
...: tokenizer = SExprTokenizer(parens='""', strict=False)
...: for sentence in sentences:
...: for item in tokenizer.tokenize(sentence):
...: print(item)
...: print("----")
...:
Well,
I've
tried
to
say
"
How
Doth
the
Little
Busy
Bee,
"
but it all came different!
----
Alice replied in a very melancholy voice. She continued, 'I'll try again.'
也有类似的线程,比如this和{a3},但是它们都建议使用基于regex的方法,但是,我很好奇是否可以仅使用nltk
来解决这个问题-听起来像是自然语言处理中的一个常见任务。在
实际上,
SExprTokenizer
也是一种基于regex的方法,可以从链接到的源代码中看到。从资料来源也可以看出,作者显然没有考虑到开头和结尾的“paren”是用同一个字符来表示的。 嵌套的深度在同一次迭代中增加或减少,因此标记器看到的引号是空字符串。在
我认为,在NLP中识别引号并不常见。 人们用很多不同的方式使用引号(特别是当你处理不同的语言时……),所以很难用一种健壮的方法来正确地使用引号。 对于许多NLP应用程序引用只是被忽略了,我想说。。。在
相关问题 更多 >
编程相关推荐