2015-02-05 24 views
0

我已經爲需要文本輸入的場景創建了依賴關係圖。如何獲得包含Stanford NLP解析器中「根」修飾符依賴項的邊緣?

SemanticGraph dependencies = sentence.get(CollapsedCCProcessedDependenciesAnnotation.class); 

我成功地使用下面的代碼讓「民」修改相關性:

List<SemanticGraphEdge> edgesContainingNumModifierDependency = dependencies.findAllRelns(GrammaticalRelation.valueOf("num")); 

不過,我想找到有關「根」的邊緣,因此,以下

List<SemanticGraphEdge> edgesContainingRootModifierDependency = dependencies.findAllRelns(GrammaticalRelation.valueOf("root")); 

似乎不起作用。

任何人都可以解釋爲什麼嗎?我如何才能獲得根的邊緣?

回答

1

我們實際上並沒有在根字和虛擬節點ROOT之間存儲SemanticGraphEdge。 (您可以看到,在公共方法like toList中手動添加了依賴關係)。

SemanticGraph documentation

根不處於表示爲圖中的一個頂點存在。目前,您需要從單獨的根變量中獲取根/根,並瞭解它。這應該可能會改變,否則,像從圖中獲取節點或邊的集合一樣,不會給你根節點或邊。

雖然您可以通過SemanticGraph#getFirstRoot獲得想要的結果。

+0

謝謝,它工作:) – 2015-02-11 17:42:16