Java 如何打印依赖关系图的一部分
我想打印依赖关系图的子树。特别是对于句子“Java 如何打印依赖关系图的一部分,java,nlp,stanford-nlp,Java,Nlp,Stanford Nlp,我想打印依赖关系图的子树。特别是对于句子“I转动红肉”和起始词meat NN,输出应该是:“红肉” 现在我是这样做的: protected String printSubGraph(IndexedWord startingWord, SemanticGraph graph) { Iterable<SemanticGraphEdge> outiter = graph.outgoingEdgeIterable(startingWord); // set the defa
I转动红肉
”和起始词meat NN
,输出应该是:“红肉
”
现在我是这样做的:
protected String printSubGraph(IndexedWord startingWord, SemanticGraph graph) {
Iterable<SemanticGraphEdge> outiter = graph.outgoingEdgeIterable(startingWord);
// set the default bounds to the startingWord
int start = startingWord.beginPosition();
int end = startingWord.endPosition();
// search the next level for larger bounds
// assume that everything in between the bounds belongs to the sub-graph of the startingWord
for (SemanticGraphEdge edge : outiter) {
start = Math.min(start, edge.getGovernor().beginPosition());
start = Math.min(start, edge.getDependent().beginPosition());
end = Math.max(end, edge.getGovernor().endPosition());
end = Math.max(end, edge.getDependent().endPosition());
}
return graph.toRecoveredSentenceString().substring(start, end);
}
受保护的字符串打印子图(IndexedWordStartingWord、SemanticGraph图){
Iterable outiter=图形。outgoingEdgeIterable(startingWord);
//将默认边界设置为startingWord
int start=startingWord.beginPosition();
int end=startingWord.endPosition();
//搜索下一个级别以获得更大的边界
//假设边界之间的所有内容都属于startingWord的子图
for(SemanticGraphEdge:outiter){
start=Math.min(start,edge.getGovernor().beginPosition());
start=Math.min(start,edge.getDependent().beginPosition());
end=Math.max(end,edge.getGovernor().endPosition());
end=Math.max(end,edge.getDependent().endPosition());
}
返回graph.toRecoveredSentenceString()子字符串(开始、结束);
}
这是不好的,原因有三:
有没有一种方法可以从SemanticGraph或CoreMap中获取此子树(并且仅此子树),而无需自己实现DFS?我知道,但我不知道如何在树中定位IndexedWord。也许您要找的不是依赖项解析,而是短语结构解析 你的判决是: 我把红肉翻过来 其短语结构解析为: (根 (S) (NP(PRP I)) (副总裁(VBP轮) (NP(DT)(JJ红)(NN肉))) (……)) 您可以填写以下表格的一部分: NP<(NN<肉) 获取所需子树或 NP
获取所有名词短语。也许您要找的不是依赖项分析,而是短语结构分析 你的判决是: 我把红肉翻过来 其短语结构解析为: (根 (S) (NP(PRP I)) (副总裁(VBP轮) (NP(DT)(JJ红)(NN肉))) (……)) 您可以填写以下表格的一部分: NP<(NN<肉) 获取所需子树或 NP 获取所有名词短语