斯坦福nlp:解析树
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了斯坦福nlp:解析树相关的知识,希望对你有一定的参考价值。
我有这句话:My dog also likes eating sausage.
我得到以下解析树:
(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();
}
以上是关于斯坦福nlp:解析树的主要内容,如果未能解决你的问题,请参考以下文章