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

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

maven

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

LexicalizedParser

Lexical是词汇的意思,LexicalizedParser即词汇的语法解析
    @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

输出

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值