2013-10-17 36 views
8

我将使用Stanford Corenlp 2013来查找短语头。我看到了this thread使用Stanford Parser(CoreNLP)查找短语头

但是,得到的答复是,我不清楚,我不能添加任何评论继续该线程。所以,我很抱歉重复。

我目前所面对的是什么(使用斯坦福Corenlp)一个句子解析树(我也试图与它由斯坦福Corenlp创建CONLL格式)。而我所需要的正是名词短语的头脑。

我不知道我该如何使用依赖性和解析树中提取nounphrases的头。 我知道的是,如果我有nsubj (x, y),y是主题的头。如果我有dobj(x,y),y是直接对象的头部。 f我有iobj(x,y),y是间接对象的头部。

不过,我不知道这办法是找到所有短语头的正确方法。如果是,我应该添加哪些规则以获得所有名词短语的头像?

也许,这是值得一说的是,我需要名词短语的头在Java代码。

回答

7

因为我不能对切塔尼亚给出的答案评论,添加更多的他的答案在这里。

斯坦福CoreNLP套房设有执行柯林斯头取景启发式和在

  1. 形式语义头取景启发式CollinsHeadFinder
  2. ModCollinsHeadFinder
  3. SemanticHeadFinder

所有你需要的是实例化三者之一并执行以下操作。

Tree tree = sentence.get(TreeCoreAnnotations.TreeAnnotation.class); 
headFinder.determineHead(tree).pennPrint(out); 

您可以遍历树的节点并根据需要确定首字。

PS:我的答案是基于释放的20140104.

这里StanfordCoreNLP套件是一个简单的DFS,可以让你提取所有的名词短语中心词在句子中

public static void dfs(Tree node, Tree parent, HeadFinder headFinder) { 
     if (node == null || node.isLeaf()) { 
     return; 
     } 
     //if node is a NP - Get the terminal nodes to get the words in the NP  
     if(node.value().equals("NP")) { 

     System.out.println(" Noun Phrase is "); 
     List<Tree> leaves = node.getLeaves(); 

     for(Tree leaf : leaves) { 
      System.out.print(leaf.toString()+" "); 

     } 
     System.out.println(); 

     System.out.println(" Head string is "); 
     System.out.println(node.headTerminal(headFinder, parent)); 

    } 

    for(Tree child : node.children()) { 
     dfs(child, node, headFinder); 
    } 

} 
相关问题