完善注释,规范流实例化时使用StandardCharsets常量;
This commit is contained in:
parent
43e3ba1c9d
commit
07d1c132a7
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* IK 中文分词 版本 7.0
|
||||
* IK Analyzer release 7.0
|
||||
* update by 高志成(magese@live.cn)
|
||||
* IK 中文分词 版本 7.4
|
||||
* IK Analyzer release 7.4
|
||||
* update by Magese(magese@live.cn)
|
||||
*/
|
||||
package org.wltea.analyzer.dic;
|
||||
|
||||
@ -9,6 +9,7 @@ import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
@ -16,7 +17,7 @@ import org.wltea.analyzer.cfg.Configuration;
|
||||
import org.wltea.analyzer.cfg.DefaultConfig;
|
||||
|
||||
/**
|
||||
* 词典管理类,单子模式
|
||||
* 词典管理类,单例模式
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public class Dictionary {
|
||||
@ -45,6 +46,11 @@ public class Dictionary {
|
||||
*/
|
||||
private Configuration cfg;
|
||||
|
||||
/**
|
||||
* 私有构造方法,阻止外部直接实例化本类
|
||||
*
|
||||
* @param cfg ik分词器配置实例
|
||||
*/
|
||||
private Dictionary(Configuration cfg) {
|
||||
this.cfg = cfg;
|
||||
this.loadMainDict();
|
||||
@ -84,15 +90,19 @@ public class Dictionary {
|
||||
/**
|
||||
* 重新更新词典
|
||||
* 由于停用词等不经常变也不建议常增加,故这里只修改动态扩展词库
|
||||
*
|
||||
* @param inputStreamList 词典文件IO流集合
|
||||
*/
|
||||
public static void reloadDic(List<InputStream> inputStreamList) {
|
||||
// 如果本类单例尚未实例化,则先进行初始化操作
|
||||
if (singleton == null) {
|
||||
Configuration cfg = DefaultConfig.getInstance();
|
||||
initial(cfg);
|
||||
}
|
||||
// 对词典流集合进行循环读取,将读取到的词语加载到主词典中
|
||||
for (InputStream is : inputStreamList) {
|
||||
try {
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(is, "UTF-8"), 512);
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8), 512);
|
||||
String theWord;
|
||||
do {
|
||||
theWord = br.readLine();
|
||||
@ -206,7 +216,7 @@ public class Dictionary {
|
||||
}
|
||||
|
||||
try {
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(is, "UTF-8"), 512);
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8), 512);
|
||||
String theWord;
|
||||
do {
|
||||
theWord = br.readLine();
|
||||
@ -247,7 +257,7 @@ public class Dictionary {
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(is, "UTF-8"), 512);
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8), 512);
|
||||
String theWord;
|
||||
do {
|
||||
theWord = br.readLine();
|
||||
@ -292,7 +302,7 @@ public class Dictionary {
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(is, "UTF-8"), 512);
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8), 512);
|
||||
String theWord;
|
||||
do {
|
||||
theWord = br.readLine();
|
||||
@ -330,7 +340,7 @@ public class Dictionary {
|
||||
throw new RuntimeException("Quantifier Dictionary not found!!!");
|
||||
}
|
||||
try {
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(is, "UTF-8"), 512);
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8), 512);
|
||||
String theWord;
|
||||
do {
|
||||
theWord = br.readLine();
|
||||
|
Loading…
x
Reference in New Issue
Block a user