首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >提取中心名词

提取中心名词
EN

Stack Overflow用户
提问于 2015-03-26 04:05:42
回答 1查看 416关注 0票数 0

我想知道我们如何提取中心名词?我使用了一个不起作用的选民解析器,但我想我必须使用依赖解析器。我运行了这个演示代码,但它给了我一个错误的答案。

代码语言:javascript
复制
public class dependencydemo {
  public static void main(String[] args) throws IOException {
    PrintWriter out;
    if (args.length > 1) {
      out = new PrintWriter(args[1]);
    } else {
      out = new PrintWriter(System.out);
    }



    StanfordCoreNLP pipeline = new StanfordCoreNLP();
    Annotation annotation;
    if (args.length > 0) {
      annotation = new       ` 
 Annotation(IOUtils.slurpFileNoExceptions(args[0]));`
    } else {
      annotation = new Annotation("Yesterday, I went to the Dallas `Country Club to play 25 cent Bingo.  While I was there I talked to my `friend Jim and we both agree that those people in Washington are `destroying our economy.");`
    }

    pipeline.annotate(annotation);
    pipeline.prettyPrint(annotation, out);


    List<CoreMap> sentences = `annotation.get(CoreAnnotations.SentencesAnnotation.class);`
    if (sentences != null && sentences.size() > 0) {
      CoreMap sentence = sentences.get(0);
      Tree tree = `sentence.get(TreeCoreAnnotations.TreeAnnotation.class);`
     // out.println();
    //  out.println("The first sentence parsed is:");
      tree.pennPrint(out);
    }
   }   

输出:

代码语言:javascript
复制
(ROOT
  (S
    (NP-TMP (NN Yesterday))
    (, ,)
    (NP (PRP I))
    (VP (VBD went)
      (PP (TO to)
        (NP (DT the) (NNP Dallas) (NNP Country) (NNP Club)))
      (S
        (VP (TO to)
          (VP (VB play)
            (S
              (NP (CD 25) (NN cent))
              (NP (NNP Bingo)))))))
    (. .)))

依赖关系:

代码语言:javascript
复制
root(ROOT-0, went-4)
tmod(went-4, Yesterday-1)
nsubj(went-4, I-3)
det(Club-9, the-6)
nn(Club-9, Dallas-7)
nn(Club-9, Country-8)
prep_to(went-4, Club-9)
aux(play-11, to-10)
xcomp(went-4, play-11)
num(cent-13, 25-12)
nsubj(Bingo-14, cent-13)
xcomp(play-11, Bingo-14)

我怎样才能从中提取中心名词?除了它似乎输出是不正确的。

EN

回答 1

Stack Overflow用户

发布于 2015-03-28 10:44:33

你在评论中的解释给我的印象是,你想要所有名词短语的中心成分。使用CoreNLP很容易做到这一点。

  1. 首先,找到所有名词短语。您可以使用一个简单的Tregex模式(参见Chris Manning's relevant answer).
  2. You可以使用CoreNLP“中心查找器”来选择匹配名词短语的句法中心成分)来完成此操作。例如,参见the ModCollinsHeadFinder.

演示代码如下。

代码语言:javascript
复制
// Fetch a head finder.
HeadFinder hf = new PennTreebankLanguagePack().headFinder();

Tree myTree = ...
TregexPattern tPattern = TregexPattern.compile("NP");
TregexMatcher tMatcher = tPattern.matcher(myTree);
while (tMatcher.find()) {
  Tree nounPhrase = tMatcher.getMatch();

  Tree headConstituent = hf.determineHead(nounPhrase);
  System.out.println(headConstituent);
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29265488

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档