SpringBoot使用Hanlp配置词典相对路径时,加载失败

  1. 配置如下
  2. 代码如下
    public static void main(String args) throws IOException {
    Sentence analyze=NLPTokenizer.analyze(“我的名字叫邓欣雨”);
    for (IWord iWord : analyze.wordList) {
    System.out.println(iWord);
    }
    }
  3. 报错如下
    十月 11, 2022 10:32:42 上午 com.hankcs.hanlp.corpus.io.ByteArrayStream createByteArrayStream
    警告: 打开失败:data/model/perceptron/large/cws.bin
    Exception in thread “main” java.lang.ExceptionInInitializerError
    at com.huinidt.admin.utils.HanLPUtils.main(HanLPUtils.java:99)
    Caused by: java.lang.RuntimeException: java.io.IOException: data/model/perceptron/large/cws.bin 加载失败
    at com.hankcs.hanlp.tokenizer.NLPTokenizer.(NLPTokenizer.java:43)
    … 1 more
    Caused by: java.io.IOException: data/model/perceptron/large/cws.bin 加载失败
    at com.hankcs.hanlp.model.perceptron.model.LinearModel.load(LinearModel.java:390)
    at com.hankcs.hanlp.model.perceptron.model.LinearModel.(LinearModel.java:65)
    at com.hankcs.hanlp.model.perceptron.PerceptronLexicalAnalyzer.(PerceptronLexicalAnalyzer.java:70)
    at com.hankcs.hanlp.model.perceptron.PerceptronLexicalAnalyzer.(PerceptronLexicalAnalyzer.java:95)
    at com.hankcs.hanlp.tokenizer.NLPTokenizer.(NLPTokenizer.java:39)
    … 1 more

https://github.com/hankcs/HanLP/pull/254
具体解决方案查看上方链接