斯坦福自然语言处理:解析树

3
我有这句话:我的狗也喜欢吃香肠。 我得到了以下的句法树:
(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();

你是否只需要句子的片段? - unknown
我只想检索语法树的那些部分! - user3318618
我想要类似这样的东西:链接 - user3318618
你的问题不够清晰。你所说的“语法类别”是什么意思?叶子级别的注释是词性标记。你是不是只是在寻找比这些标记高一级的注释? - Aditya Mukherji
是的,它应该要提升到更高的水平!我会感兴趣了解那些提取这些数据的工具:[链接](http://s27.postimg.org/97ngmxg0j/Immagine.png) - user3318618
你需要的是一个块分析器,而不是解析器。你可以尝试使用YamCha - scozy
1个回答

4
从句子注释中,您可以获得各种类型的依赖词集合。这可能是您正在寻找的“更高级别”的内容。
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();                                                    
}      

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接