无法从opennlp Chunking解析器的结果中提取名词短语

时间:2013-07-22 06:01:11

标签: java parsing opennlp chunking

您好我使用了openNLP分块解析器并解析了一些文本并在下面的堆栈溢出问题的帮助下我试图只提取名词短语

How to extract the noun phrases using Open nlp's chunking parser

但我无法提取名词短语,下面是我的代码

public class keywords {
    List<Parse> nounPhrases;
    public static void main(String args[])throws InvalidFormatException, IOException {
        InputStream is = new FileInputStream("en-parser-chunking.bin");

        ParserModel model = new ParserModel(is);

        opennlp.tools.parser.Parser parser = ParserFactory.create(model);

        String sentence = "Programcreek is a very huge and useful website";
        Parse topParses[] = ParserTool.parseLine(sentence, parser, 1);

        for (Parse p : topParses)
        {
            p.show();
            p.toString();
        }
        is.close();

    }
    public void getNounPhrases(Parse p) {
        if (p.getType().equals("NP")) {
             nounPhrases.add(p);
        }
        for (Parse child : p.getChildren()) {
             getNounPhrases(child);
        }
    }

}

请建议我从解析的内容中提取NP

谢谢

1 个答案:

答案 0 :(得分:0)

您应该以令牌格式传递字符串,如下所示:

new String[]{"Programcreek ",
             "is",
             "a",
             "very",
             "huge",
             };