zoukankan      html  css  js  c++  java
  • 分析器 OpenNLP

    7 分析器

    功能介绍:尝试解析器最简单的方法是在命令行工具。该工具仅用于演示和测试。请从我们网站上的英文分块解析器模型,并用以下命令启动解析工具。

    代码实现:

    package package01;
    
    import opennlp.tools.cmdline.parser.ParserTool;
    import opennlp.tools.parser.Parser;
    import opennlp.tools.parser.ParserFactory;
    import opennlp.tools.parser.ParserModel;
    import opennlp.tools.util.InvalidFormatException;
    
    import java.io.FileInputStream;
    import java.io.IOException;
    import java.io.InputStream;
    
    public class Test07 {
    
        public static void main(String[] args) throws IOException {
            Test07.Parse();
        }
    
        /**
         * 6.分析器: Parser
         * @deprecated Given this sentence: "Programcreek is a very huge and useful website.", parser can return the following:
         * (TOP (S (NP (NN Programcreek) ) (VP (VBZ is) (NP (DT a) (ADJP (RB very) (JJ huge) (CC and) (JJ useful) ) ) ) (. website.) ) )
         * (TOP
         *     (S
         *        (NP
         *           (NN Programcreek)
         *        )
         *        (VP
         *           (VBZ is)
         *           (NP
         *              (DT a)
         *              (ADJP
         *                   (RB very)
         *                   (JJ huge)
         *                   (CC and)
         *                   (JJ userful)
         *              )
         *           )
         *        )
         *        (. website.)
         *     )
         * )
         * @param str
         */
        public static void Parse() throws InvalidFormatException, IOException {
            // http://sourceforge.net/apps/mediawiki/opennlp/index.php?title=Parser#Training_Tool
            InputStream is = new FileInputStream("E:\NLP_Practics\models\en-parser-chunking.bin");
            ParserModel model = new ParserModel(is);
            Parser parser = ParserFactory.create(model);
            String sentence = "Programcreek is a very huge and useful website.";
            opennlp.tools.parser.Parse topParses[] = ParserTool.parseLine(sentence, parser, 1);
            for (opennlp.tools.parser.Parse p : topParses) {
                p.show();
            }
            is.close();
        }
    }
    

      

    结果

    (TOP (S (NP (NN Programcreek)) (VP (VBZ is) (NP (DT a) (ADJP (RB very) (JJ huge) (CC and) (JJ useful)))) (. website.)))
    

      

    https://github.com/godmaybelieve
  • 相关阅读:
    忍道
    2020.12.27
    2020.12.26
    2020.12.25
    记录
    卸载抖音
    汉化报告修改配置文件
    tcp校验client客户端的合法性
    tcp连接发送命令客户端接收后返回结果给服务端
    logging模块
  • 原文地址:https://www.cnblogs.com/yuyu666/p/15029827.html
Copyright © 2011-2022 走看看