使用Stanford Parser(CoreNLP)查找短语头 [英] Using Stanford Parser(CoreNLP) to find phrase heads

查看:1045
本文介绍了使用Stanford Parser(CoreNLP)查找短语头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将使用Stanford Corenlp 2013找到短语标题。我看到了这个主题

I am going to use Stanford Corenlp 2013 to find phrase heads. I saw this thread.

但是,答案对我来说并不清楚,我无法添加任何评论来继续该线程。所以,我很抱歉重复。

But, the answer was not clear to me and I couldn't add any comment to continue that thread. So, I'm sorry for duplication.

我现在所拥有的是句子的解析树(使用Stanford Corenlp)(我也尝试过CONLL格式,由斯坦福Corenlp创建。而我所需要的只是名词短语的头部。

What I have at the moment is the parse tree of a sentence (using Stanford Corenlp) (I also tried with CONLL format which is created by Stanford Corenlp). And what I need is exactly the head of noun phrases.

我不知道如何使用依赖关系和解析树来提取名词短语的头部。
我所知道的是,如果我有 nsubj(x,y),则y是该主题的负责人。如果我有 dobj(x,y),则y是直接对象的头部。 f我有 iobj(x,y),y是间接对象的头部。

I don't know how I can use dependencies and the parse tree to extract heads of nounphrases. What I know is that if I have nsubj (x, y), y is the head of the subject. If I have dobj(x,y), y is the head of the direct object. f I have iobj(x,y), y is the head of the indirect object.

但是,我我不确定这种方式是否是找到所有短语头的正确方法。如果是,我应该添加哪些规则来获取所有名词短语?

However, I am not sure if this way is the correct way to find all phrase heads. If it is, which rules I should add to get all heads of noun phrases?

也许,值得说的是我需要java代码中的名词短语的头部。

Maybe, it is worth saying that I need the heads of noun phrases in a java code.

推荐答案

由于我无法对Chaitanya给出的答案发表评论,所以在这里补充更多答案。

Since I couldnt comment on the answer given by Chaitanya, adding more to his answer here.

Stanford CoreNLP套件实现了Collins头部探测器启发式和语义头部探测器启发式,其形式为

Stanford CoreNLP suite has implementation of Collins head finder heuristics and a semantic head finder heuristic in the form of


  1. CollinsHeadFinder

  2. ModCollinsHeadFinder

  3. SemanticHeadFinder

你需要的只是实例化三个中的一个并执行以下操作。

All you would need is instantiate one of the three and do the following.

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

您可以遍历树的节点并在需要的地方确定头字。

You can iterate through the nodes of the tree and determine head words wherever required.

PS:我的回答基于截至20140104年发布的StanfordCoreNLP套件。

PS: My answer is based on the StanfordCoreNLP suite released as of 20140104.

这是一个简单的dfs,可以让你提取头部句子中所有名词短语的单词

Here is a simple dfs that lets you extract head words for all noun phrases in a sentence

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

 }

这篇关于使用Stanford Parser(CoreNLP)查找短语头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆