我正在使用Stanford CoreNLP来获取句子的依赖树.我遇到的问题是,对于某些句子,树没有根节点.这可能吗?
这里有一个类似的例子,其中检测到的问题是打印方法(即有一个根,但不知何故它没有被打印).
但是,在我的情况下,句子根本没有根.这是我的测试句子:"(Wendigo是)为什么我们去看电影:通过眼睛,心脏和头脑喂养."
我正在使用以下代码打印依赖项:
SemanticGraph dependencies = sentence.get(CollapsedCCProcessedDependenciesAnnotation.class);
out.println(dependencies.toString("plain"));
Run Code Online (Sandbox Code Playgroud)
这是输出:
nsubj(-RRB--4, Wendigo-2)
cop(-RRB--4, is-3)
advmod(go-7, why-5)
nsubj(go-7, we-6)
advcl(-RRB--4, go-7)
det(cinema-10, the-9)
prep_to(go-7, cinema-10)
aux(fed-14, to-12)
auxpass(fed-14, be-13)
parataxis(go-7, fed-14)
det(eye-17, the-16)
prep_through(fed-14, eye-17)
det(heart-20, the-19)
appos(eye-17, heart-20)
det(mind-23, the-22)
appos(heart-20, mind-23)
Run Code Online (Sandbox Code Playgroud)
尝试手动打印根节点后,使用以下代码:
IndexedWord root = dependencies.getFirstRoot();
out.printf("ROOT(root-0, %s-%d)%n", root.word(), root.index());
Run Code Online (Sandbox Code Playgroud)
我收到以下错误消息:
Exception in thread "main" java.lang.RuntimeException: No roots in graph:
dep reln gov
--- ---- ---
Wendigo-2 nsubj -RRB--4
is-3 cop -RRB--4
why-5 advmod go-7
we-6 nsubj …Run Code Online (Sandbox Code Playgroud)