我正在研究以下问题:我想使用 Stanford CoreNLP 将句子拆分为子句。例句可以是:
"Richard is working with CoreNLP, but does not really understand what he is doing"
我现在希望将我的句子拆分为单个“S”,如下面的树状图所示:
我希望输出是一个带有单个“S”的列表,如下所示:
['Richard is working with CoreNLP', ', but', 'does not really understand what', 'he is doing']
如果有任何帮助,我将不胜感激 :)
最佳答案
我怀疑您正在寻找的工具是 Tregex ,电源点中有更详细的描述 here或 Javadoc类本身。
在您的情况下,我相信您正在寻找的模式只是S
。所以,像这样:
tregex.sh “S” <path_to_file>
文件是 Penn Treebank 格式的树——也就是说,类似于 (ROOT (S (NP (NNS dogs)) (VP (VB chase) (NP (NNS cats)))))
.
顺便说一句:我相信片段“,但是”实际上并不是一个句子,正如您在图中突出显示的那样。相反,您突出显示的节点包含整个句子“Richard is working with CoreNLP, but does not really understand what he is doing”。然后 Tregex 会将整个句子作为匹配项之一打印出来。类似地,“does not really understand what”不是一个句子,除非它包含整个 SBAR:“does not understand what he is doing”。
如果您只想要“叶子”句子(即一个句子不包含在另一个句子中),您可以尝试更像这样的模式:
S !>> S
注意:我没有测试这些模式——使用风险自负!
关于nlp - 使用 CoreNLP 将句子分割成子句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53155057/