前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >使用stanford nlp进行依存句法分析

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

作者头像
code4it
发布2018-09-17 16:06:44
2.2K0
发布2018-09-17 16:06:44
举报
文章被收录于专栏:码匠的流水账码匠的流水账

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

maven

代码语言:javascript
复制
        <dependency>
            <groupId>edu.stanford.nlp</groupId>
            <artifactId>stanford-corenlp</artifactId>
            <version>3.9.1</version>
        </dependency>

LexicalizedParser

Lexical是词汇的意思,LexicalizedParser即词汇的语法解析

代码语言:javascript
复制
    @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

输出

代码语言:javascript
复制
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依存句法关系解释
本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2018-04-04,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 码匠的流水账 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • maven
  • LexicalizedParser
    • 关系说明
      • 词性说明
      • 小结
      • doc
      领券
      问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档