gpt4 book ai didi

java - 斯坦福 nlp : Parse Tree

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:14:38 24 4
gpt4 key购买 nike

我有这样一句话:我的狗也喜欢吃香肠。

我得到以下解析树:

(ROOT
(S
(NP (PRP$ My) (NN dog))
(ADVP (RB also))
(VP (VBZ likes)
(S
(VP (VBG eating)
(NP (NN sausage)))))
(. .)))

如何只获取语法类别,即:NP、ADVP、VP 等?

我试过这段代码:

  Tree t=sentence.get(TreeAnnotation.class);
t.labels();

最佳答案

从句子注释中,您可以获得各种类型的相关词集合。这可能是您正在寻找的“下一个级别”。

Tree tree = sentenceAnnotation.get(TreeAnnotation.class);                             
// print the tree if needed
SemanticGraph basic = sentenceAnnotation.get(BasicDependenciesAnnotation.class);
Collection<TypedDependency> deps = basic.typedDependencies();
for (TypedDependency typedDep : deps) {
GrammaticalRelation reln = typedDep.reln();
String type = reln.toString();
}

SemanticGraph colapsed = sentenceAnnotation
.get(CollapsedDependenciesAnnotation.class);
Collection<TypedDependency> deps = colapsed.typedDependencies();
for (TypedDependency typedDep : deps) {
GrammaticalRelation reln = typedDep.reln();
String type = reln.toString();
}

SemanticGraph ccProcessed = sentenceAnnotation
.get(CollapsedCCProcessedDependenciesAnnotation.class);
Collection<TypedDependency> deps = ccProcessed.typedDependencies();
for (TypedDependency typedDep : deps) {
GrammaticalRelation reln = typedDep.reln();
String type = reln.toString();
}

关于java - 斯坦福 nlp : Parse Tree,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22410265/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com