Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/tfs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何打印依赖关系图的一部分_Java_Nlp_Stanford Nlp - Fatal编程技术网

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()子字符串(开始、结束);
}
这是不好的,原因有三:

  • 我假设标记之间的所有内容都属于起始词的子树
  • 我不会在整个子树中搜索更大的边界
  • 我假设图形是整个文本,并且边界对于RecoveredSentenceString是有效的。(如果原文包含多个句子,则不正确。)

  • 有没有一种方法可以从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

    获取所有名词短语