zoukankan      html  css  js  c++  java
  • HanLP测试代码

    在项目的src/main/resources下新建一个文本文件 testdata.txt

    测试代码

    package package03;
    
    import com.hankcs.hanlp.seg.common.Term;
    import com.hankcs.hanlp.tokenizer.NLPTokenizer;
    
    import java.io.*;
    import java.util.List;
    
    public class Main {
        private String text;
    
        public static void main(String[] args) {
            String fileName = Main.class.getResource("/testdata.txt").getFile();
            File file = new File(fileName);
            BufferedReader br;
            StringBuffer sb = new StringBuffer();
            try {
                br = new BufferedReader(new FileReader(file));
                while (br.ready()) {
                    sb.append(br.readLine().concat("
    "));
                }
                br.close();
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
            final String text = sb.toString();
            List<Term> terms = NLPTokenizer.segment(text);
            System.out.println(terms);
        }
    }
    

      

    <!-- hanlp -->
    <dependency>
    <groupId>com.hankcs</groupId>
    <artifactId>hanlp</artifactId>
    <version>portable-1.7.8</version>
    </dependency>
    https://github.com/godmaybelieve
  • 相关阅读:
    9、UmbracoNewsSite:分页
    7、UmbracoNewsSite:新闻详情页
    6、UmbracoNewsSite:添加新闻分类
    5、UmbracoNewsSite:添加css和js文件
    3、UmbracoNewsSite:文档类型设置
    书单
    文章
    Django-rest framework框架
    Django框架
    前端快速入门
  • 原文地址:https://www.cnblogs.com/yuyu666/p/15031376.html
Copyright © 2011-2022 走看看