分词es路径修改
This commit is contained in:
parent
96cb0d6cc3
commit
2f02ecfe67
@ -10,9 +10,11 @@ package com.suisung.mall.common.utils;
|
||||
|
||||
import com.huaban.analysis.jieba.JiebaSegmenter;
|
||||
import com.huaban.analysis.jieba.WordDictionary;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.net.URISyntaxException;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.*;
|
||||
@ -36,7 +38,6 @@ public class JiebaUtils {
|
||||
private static final String PROTECT_START = "开始";
|
||||
private static final String PROTECT_END = "结束";
|
||||
|
||||
|
||||
// 正则模式:匹配数字+单位的组合
|
||||
private static final String PROTECT_UNIT = "__UNIT__";
|
||||
private static final String PROTECT_SPEC = "__SPEC__";
|
||||
@ -70,16 +71,12 @@ public class JiebaUtils {
|
||||
private static void loadUserDict() {
|
||||
// 方法1:通过文件加载
|
||||
WordDictionary dictionary = WordDictionary.getInstance();
|
||||
|
||||
Path path = null;
|
||||
try {
|
||||
path = Paths.get(Objects.requireNonNull(JiebaUtils.class.getClassLoader()
|
||||
.getResource("dic/userdict.txt")).toURI());
|
||||
} catch (URISyntaxException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
if(path.toFile().exists()){
|
||||
Resource resource=new ClassPathResource("dic/user_dict.txt");
|
||||
Path path = Paths.get(resource.getURI());
|
||||
dictionary.loadUserDict(path);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user