こんにちは、私は openNLP チャンキング パーサーを使用していくつかのテキストを解析しました。以下のスタック オーバーフローの質問の助けを借りて、名詞句のみを抽出しようとしました
Open nlp のチャンキング パーサーを使用して名詞句を抽出する方法
しかし、名詞句を抽出できませんでした。以下は私のコードです
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を抽出することを提案してください
ありがとう