在java中使用opennlp提取名词短语

在java中使用opennlp提取名词短语,java,nlp,text-processing,opennlp,Java,Nlp,Text Processing,Opennlp,我试图从句子中提取名词短语。我正在使用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.

我试图从句子中提取名词短语。我正在使用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);
          }
     }                                        
  }
如何从结果中提取名词短语


任何帮助都将不胜感激

您可以从中提取
NP
s,但有一种模型只进行组块(即名词短语检测),而不使用语法。这可能更容易使用(但它需要标记化和词性标记步骤才能运行)。

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

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


当我这样做时,我得到了以下结果:B-npi-npb-npi-npb-vpb-npi-npi-NP-npb-SBAR B-NP B-VP i-VP i-VP B-ppb-NP i-npb-vpb-ppb-NP i-NP[0..2..3]PP[3..6..7)VP[7..10..11..12..16..17)PP[17..19..20]VP[20..21][21..23)NP但我想得到正确的句子。我将如何得到它?请参阅以了解名词短语标记的含义。我如何从这些分块数据中获得实体???@DanielNaber
(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.)))))))))))  
(PP 
    (IN as) 
        (NP 
            (DT this) (NN when) (NN flown)
        )
    )
)