【问题标题】:Stanford nlp: Parse Tree斯坦福 nlp:解析树
【发布时间】:2014-04-20 01:19:19
【问题描述】:

我有这句话: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();

【问题讨论】:

  • 你只需要一个句子的块吗?
  • 我只想检索解析树的那些部分!
  • 我想要这样的东西:link
  • 您的问题不清楚。你说的语法类别是什么意思?叶级注释是词性标签。您只是在寻找比它们高一级的注释吗?
  • 对,应该是上一层!我会对那些提取这些的人感兴趣:link

标签: java nlp stanford-nlp


【解决方案1】:

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

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();                                                    
}      

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多