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