【问题标题】:extract noun phrases using opennlp in java在java中使用opennlp提取名词短语
【发布时间】:2015-03-29 22:04:42
【问题描述】:

我正在尝试从句子中提取名词短语。我正在使用 opennlp 库“en-parser-chunking.bin”。

代码示例:

 ArrayList<opennlp.tools.parser.Parse> nounPhrases = new ArrayList<>();

 searchmethod("what is the nickname of the British flag?");
 for(int t =0; t<50; t++)
 {
     str= text.get(t);
     InputStream is = new FileInputStream("en-parser-chunking.bin");
     ParserModel model = new ParserModel(is);
     opennlp.tools.parser.Parser parser = ParserFactory.create(model);
     opennlp.tools.parser.Parse[] topParses = ParserTool.parseLine(str, parser, 1);
     for (opennlp.tools.parser.Parse p : topParses){
          p.show();
          if (p.getType().equals("NP")) {
              nounPhrases.add(p);
          }
     }                                        
  }

使用此代码,我得到以下结果:

(TOP (S (NP (NP (DT The) (NN nickname)) (PP (IN for) (NP (DT the) (JJ British) (NN flag)))) (VP (VBZ is) (NP (NP (DT the) (NNP Union) (NNP Jack.)) (SBAR (IN Although) (S (NP (PRP it)) (VP (VBZ is) (ADVP (RB only) (RB correctly)) (VP (VBN known) (PP (IN as) (NP (DT this) (NN when) (NN flown))) (PP (IN on) (NP (DT a) (NN ship.)))))))))))  

如何从该结果中提取名词短语?

任何帮助将不胜感激。

【问题讨论】:

    标签: java nlp text-processing opennlp


    【解决方案1】:

    您可以从中提取NPs,但http://opennlp.sourceforge.net/models-1.5/en-chunker.bin 有一个模型,它只进行分块(即名词短语检测),没有语法。这可能更容易使用(但它需要标记化和 POS 标记步骤才能运行)。

    【讨论】:

    • 当我这样做时,我得到以下结果: B-NP I-NP B-PP B-NP I-NP I-NP B-VP B-NP I-NP I-NP B- SBAR B-NP B-VP I-VP I-VP I-VP B-PP B-NP I-NP B-VP B-PP B-NP I-NP [0..2) NP [2..3) PP [3..6) NP [6..7) VP [7..10) NP [10..11) SBAR [11..12) NP [12..16) VP [16..17) PP [17..19) NP [19..20) VP [20..21) PP [21..23) NP 但我想得到正确的句子。我将如何获得它?
    • 名词短语标签的含义见stackoverflow.com/questions/15059878/…
    • 如何从分块数据中获取实体? @DanielNaber
    【解决方案2】:

    您好,我同意answer,但如果您仔细查看您的输出,则已识别树中存在问题,这将导致树检测到错误的块。

    在上面的例子中,有一个 PP 被识别为错误的,因为 flyn 永远不可能是一个 NN。我相信正确的邮寄是关键。如果您需要知道如何更正邮资,请告诉我。 谢谢。

    (PP 
        (IN as) 
            (NP 
                (DT this) (NN when) (NN flown)
            )
        )
    )
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多