斯坦福大学java老师_java-斯坦福大学nlp:解析树

论坛 期权论坛 编程之家     
选择匿名的用户   2021-5-30 19:36   17   0

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

我得到以下解析树:

(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 deps = basic.typedDependencies();

for (TypedDependency typedDep : deps) {

GrammaticalRelation reln = typedDep.reln();

String type = reln.toString();

}

SemanticGraph colapsed = sentenceAnnotation

.get(CollapsedDependenciesAnnotation.class);

Collection deps = colapsed.typedDependencies();

for (TypedDependency typedDep : deps) {

GrammaticalRelation reln = typedDep.reln();

String type = reln.toString();

}

SemanticGraph ccProcessed = sentenceAnnotation

.get(CollapsedCCProcessedDependenciesAnnotation.class);

Collection deps = ccProcessed.typedDependencies();

for (TypedDependency typedDep : deps) {

GrammaticalRelation reln = typedDep.reln();

String type = reln.toString();

}

标签:stanford-nlp,nlp,java

来源: https://codeday.me/bug/20191029/1962520.html

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP