使用opennlp进行依存句法分析
Posted 码匠的流水账
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用opennlp进行依存句法分析相关的知识,希望对你有一定的参考价值。
序
本文主要研究下如何使用opennlp进行依存句法分析
Parse
opennlp主要使用Parse来进行依存句法分析,其模型为ParserModel
@Test
public void testParserTool() throws IOException {
try (InputStream modelInputStream = this.getClass().getClassLoader().getResourceAsStream("chunker/en-parser-chunking.bin")) {
ParserModel model = new ParserModel(modelInputStream);
Parser parser = ParserFactory.create(model);
String sentence = "The cow jumped over the moon";
// Used to demonstrate difference between NER and Parser
// sentence = "He was the last person to see Fred.";
Parse parses[] = ParserTool.parseLine(sentence, parser, 3);
for (Parse parse : parses) {
parse.show();
}
} catch (IOException ex) {
ex.printStackTrace();
}
}
这里使用en-parser-chunking.bin这个训练好的模型来进行分析
第一句输出如下
(TOP (PP (S (NP (DT The) (NN cow)) (PP (VP (VBD jumped) (PRT (RP over))))) (NP (DT the) (NN moon))))
(TOP (NP (NP (DT The) (NN cow)) (PP (S (VP (VBN jumped) (PP (IN over) (NP (DT the) (NN moon))))))))
(TOP (NP (NP (DT The) (NN cow)) (SBAR (S (VP (VBN jumped) (PP (IN over) (NP (DT the) (NN moon))))))))
第二句输出如下
(TOP (FRAG (FRAG (S (NP (PRP He)) (VP (VBD was) (NP (NP (DT the) (JJ last) (NN person)) (SBAR (S (VP (TO to) (VP (VB see))))))))) (: Fred.)))
(TOP (S (S (NP (PRP He)) (VP (VBD was) (NP (NP (DT the) (JJ last) (NN person)) (PP (VP (TO to) (VP (VB see))))))) (: Fred.)))
(TOP (S (FRAG (S (NP (PRP He)) (VP (VBD was) (NP (NP (DT the) (JJ last) (NN person)) (SBAR (S (VP (TO to) (VP (VB see))))))))) (: Fred.)))
小结
opennlp也支持依存句法分析,不过根节点的表示,stanford nlp使用的是ROOT,而opennlp使用的是TOP。
doc
tools.parser.parsing
以上是关于使用opennlp进行依存句法分析的主要内容,如果未能解决你的问题,请参考以下文章
Stanford CoreNLP超简单安装及简单使用,句法分析及依存句法分析