Dependency parsing using opennlp

  nlp

Order

This paper mainly studies how to use opennlp to analyze dependency syntax

Parser

Opennlp mainly uses Parser for dependency parsing, and its model is 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();
        }
    }

Here, the trained model of en-parser-chunking.bin is used for analysis.

The output of the first sentence is as follows

(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))))))))

The output of the second sentence reads as follows

(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.)))

Summary

Opennlp also supports dependency parsing, but the representation of the ROOT node shows that stanford nlp uses root while opennlp uses TOP.

doc