0
作爲一個例子,我從斯坦福分析器得到以下解析樹。我如何提取像S和SBAR這樣的標籤以最終提取子句。我嘗試了一小段代碼(這顯然是不正確的)作爲一個起點,使用了不同的Tree方法,但沒有給出我想要的結果。解析節點標籤以可能地從句法樹中提取子句
代碼:
for (Tree subtree: parseTree.getLeaves()){
if (subtree.label().equals("S")||subtree.label().equals("SBAR"))
System.out.println("SUBTREE:::"+"\t"+ subtree.getLeaves());
}
解析樹:
(ROOT
(S
(NP
(NP (DT A) (NNP Bristol) (NN hospital))
(SBAR
(WHNP (WDT that))
(S
(VP (VBD retained)
(NP
(NP (DT the) (NNS hearts))
(PP (IN of)
(NP
(NP (CD 300) (NNS children))
(SBAR
(WHNP (WP who))
(S
(VP (VBD died)
(PP (IN in)
(NP (JJ complex) (NNS operations)))))))))))))
(VP (VBD behaved)
(ADVP (IN in) (DT a))
('' '')
(S
(VP (VBG cavalier) ('' '')
(NP (NN fashion))))
(PP (IN towards)
(NP (DT the) (NNS parents))))
(. .)))
事實上,我會建議在我的原始答案中使用Tregex。 – StanfordNLPHelp