Dependency syntax analysis using stanford nlp

  nlp

Order

This paper mainly studies how to use stanford nlp for dependency parsing

maven

        <dependency>
            <groupId>edu.stanford.nlp</groupId>
            <artifactId>stanford-corenlp</artifactId>
            <version>3.9.1</version>
        </dependency>

LexicalizedParser

Lexical is the meaning of words, LexicalizedParser is the grammatical analysis of words.

    @Test
    public void testLexicalizedParser() throws IOException {
        LexicalizedParser lp = LexicalizedParser.loadModel(this.getClass().getClassLoader().getResource("xinhuaFactoredSegmenting.ser.gz").getPath());
        List<String> lines = Arrays.asList("小明喜欢吃香蕉");
        lines.stream().forEach(sentence -> {
            Tree tree = lp.parse(sentence);
            ChineseGrammaticalStructure gs = new ChineseGrammaticalStructure(tree);
            Collection<TypedDependency> tdl = gs.typedDependenciesCollapsed();

            System.out.println("sentence:"+sentence);
            tdl.stream().forEach(typedDependency -> {
                System.out.println("Governor Word: [" + typedDependency.gov() + "] Relation: [" + typedDependency.reln().getLongName() + "] Dependent Word: [" + typedDependency.dep() + "]");
            });
        });
    }

XinhuaFactoredSegmenting.ser.gz is loaded here

Output

sentence:小明喜欢吃香蕉
Governor Word: [喜欢/VV] Relation: [nominal subject] Dependent Word: [小明/NR]
Governor Word: [ROOT] Relation: [root] Dependent Word: [喜欢/VV]
Governor Word: [喜欢/VV] Relation: [clausal complement] Dependent Word: [吃/VV]
Governor Word: [吃/VV] Relation: [direct object] Dependent Word: [香蕉/NN]

Relationship description

  • At the beginning of the root sentence, a virtual node
  • nsubj(nominal subject) noun subject
  • dobj(direct object) direct object
  • ccomp(clausal complement) clause added

Description of part of speech

  • VV verb
  • NR names
  • NN common noun

Summary

This paper uses LexicalizedParser of stanford nlp to make a simple dependency analysis on Chinese sentences. For more in-depth contents, see the following reference documents.

doc