使用stanford nlp进行依存句法分析

本文主要研究下如何使用stanford nlp进行依存句法分析

maven

        
            edu.stanford.nlp
            stanford-corenlp
            3.9.1
        

LexicalizedParser

Lexical是词汇的意思,LexicalizedParser即词汇的语法解析
    @Test
    public void testLexicalizedParser() throws IOException {
        LexicalizedParser lp = LexicalizedParser.loadModel(this.getClass().getClassLoader().getResource("xinhuaFactoredSegmenting.ser.gz").getPath());
        List lines = Arrays.asList("小明喜欢吃香蕉");
        lines.stream().forEach(sentence -> {
            Tree tree = lp.parse(sentence);
            ChineseGrammaticalStructure gs = new ChineseGrammaticalStructure(tree);
            Collection 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

输出

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]

关系说明

  • root 句子的开头,一个虚拟的node
  • nsubj(nominal subject) 名词主语
  • dobj(direct object) 直接宾语
  • ccomp(clausal complement) 从句补充

词性说明

  • VV 动词
  • NR 人名
  • NN 常用名词

小结

本文利用stanford nlp的LexicalizedParser对中文句子进行了简单的依存关系分析,更深入的内容见下面的参考文档。

doc

  • nlp stanford parser
  • ChineseGrammaticalRelations
  • nlp stanford dependencies_manual
  • Stanford-parser依存句法关系解释

你可能感兴趣的:(nlp)