嗨,我使用了 openNLP 分块解析器并解析了一些文本,并在下面的堆栈溢出问题的帮助下,我尝试仅提取名词短语
但我无法提取名词短语,下面是我的代码
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
谢谢