Skip to content

hanlp打包问题 #983

Closed
Closed
@yoopaan

Description

@yoopaan

注意事项

请确认下列注意事项:

  • 我已仔细阅读下列文档,都没有找到答案:
  • 我已经通过Googleissue区检索功能搜索了我的问题,也没有找到答案。
  • 我明白开源社区是出于兴趣爱好聚集起来的自由社区,不承担任何责任或义务。我会礼貌发言,向每一个帮助我的人表示感谢。
  • 我在此括号内输入x打钩,代表上述事项确认完毕

版本号

当前最新版本号是:1.6.8
我使用的版本是:1.6.8

我的问题

打包后找不到hanlp.properties

步骤

  1. 首先: 下载hanlp源码(master分支),在com.hankcs.hanlp.HanLP类中加了一个main方法用于测试:
    public static void main(String[] args) {
        System.out.println(HanLP.segment("商品和服务"));
    }
  1. 然后: 打包,执行打包命令 mvn clean package -Dmaven.test.skip=true

  2. 接着: 修改hanlp.properties中的root路径为data的父文件夹并放到target目录下,和hanlp-1.6.8-sources.jar、hanlp-1.6.8.jar在同一目录下,命令运行com.hankcs.hanlp.HanLP类的main方法:

java -cp hanlp-1.6.8.jar com.hankcs.hanlp.HanLP start

期望输出

[商品/n, 和/cc, 服务/vn]

期望和hanlp-1.6.8-release.zip里面打包出来的效果一样,两个jar包一个配置文件。

实际输出

sep 28, 2018 1:47:03 PM com.hankcs.hanlp.HanLP$Config <clinit>
SEVERE: 没有找到hanlp.properties,可能会导致找不到data
========Tips========
请将hanlp.properties放在下列目录:
Web项目则请放到下列目录:
Webapp/WEB-INF/lib
Webapp/WEB-INF/classes
Appserver/lib
JRE/lib
并且编辑root=PARENT/path/to/your/data
现在HanLP将尝试从/Users/pan/github/HanLP-master/target读取data……
Sep 28, 2018 1:47:03 PM com.hankcs.hanlp.corpus.io.IOUtil readBytes
WARNING: 读取data/dictionary/CoreNatureDictionary.txt.bin时发生异常java.io.FileNotFoundException: data/dictionary/CoreNatureDictionary.txt.bin (No such file or directory)
Sep 28, 2018 1:47:03 PM com.hankcs.hanlp.dictionary.CoreDictionary load
WARNING: 核心词典data/dictionary/CoreNatureDictionary.txt不存在!java.io.FileNotFoundException: data/dictionary/CoreNatureDictionary.txt (No such file or directory)
Exception in thread "main" java.lang.ExceptionInInitializerError
	at com.hankcs.hanlp.seg.common.Vertex.newB(Vertex.java:455)
	at com.hankcs.hanlp.seg.common.WordNet.<init>(WordNet.java:73)
	at com.hankcs.hanlp.seg.Viterbi.ViterbiSegment.segSentence(ViterbiSegment.java:40)
	at com.hankcs.hanlp.seg.Segment.seg(Segment.java:573)
	at com.hankcs.hanlp.tokenizer.StandardTokenizer.segment(StandardTokenizer.java:50)
	at com.hankcs.hanlp.HanLP.segment(HanLP.java:626)
	at com.hankcs.hanlp.HanLP.main(HanLP.java:860)
Caused by: java.lang.IllegalArgumentException: 核心词典data/dictionary/CoreNatureDictionary.txt加载失败
	at com.hankcs.hanlp.dictionary.CoreDictionary.<clinit>(CoreDictionary.java:44)
	... 7 more

其他信息

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions