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

使用opennlp进行依存句法分析

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

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

Parse

opennlp主要使用Parse来进行依存句法分析,其模型为ParserModel

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

这里使用en-parser-chunking.bin这个训练好的模型来进行分析

第一句输出如下

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

第二句输出如下

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

小结

opennlp也支持依存句法分析,不过根节点的表示,stanford nlp使用的是ROOT,而opennlp使用的是TOP。

doc

  • tools.parser.parsing
本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2018-04-07,如有侵权请联系 cloudcommunity@tencent.com 删除

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

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

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

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