修改读取文件逻辑优化效率,新增词典文件注释功能,#开头的词语将不会进行加载。
This commit is contained in:
parent
720278edd1
commit
98ee5afe64
|
@ -21,16 +21,13 @@
|
||||||
* 版权声明 2012,乌龙茶工作室
|
* 版权声明 2012,乌龙茶工作室
|
||||||
* provided by Linliangyi and copyright 2012 by Oolong studio
|
* provided by Linliangyi and copyright 2012 by Oolong studio
|
||||||
*
|
*
|
||||||
* 7.5版本 由 Magese (magese@live.cn) 更新
|
* 7.6版本 由 Magese (magese@live.cn) 更新
|
||||||
* release 7.5 update by Magese(magese@live.cn)
|
* release 7.6 update by Magese(magese@live.cn)
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
package org.wltea.analyzer.dic;
|
package org.wltea.analyzer.dic;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.*;
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -113,32 +110,30 @@ public class Dictionary {
|
||||||
* 重新更新词典
|
* 重新更新词典
|
||||||
* 由于停用词等不经常变也不建议常增加,故这里只修改动态扩展词库
|
* 由于停用词等不经常变也不建议常增加,故这里只修改动态扩展词库
|
||||||
*
|
*
|
||||||
* @param inputStreamList 词典文件IO流集合
|
* @param inputStreamReaderList 词典文件IO流集合
|
||||||
*/
|
*/
|
||||||
public static void reloadDic(List<InputStream> inputStreamList) {
|
public static void reloadDic(List<Reader> inputStreamReaderList) {
|
||||||
// 如果本类单例尚未实例化,则先进行初始化操作
|
// 如果本类单例尚未实例化,则先进行初始化操作
|
||||||
if (singleton == null) {
|
if (singleton == null) {
|
||||||
Configuration cfg = DefaultConfig.getInstance();
|
Configuration cfg = DefaultConfig.getInstance();
|
||||||
initial(cfg);
|
initial(cfg);
|
||||||
}
|
}
|
||||||
// 对词典流集合进行循环读取,将读取到的词语加载到主词典中
|
// 对词典流集合进行循环读取,将读取到的词语加载到主词典中
|
||||||
for (InputStream is : inputStreamList) {
|
for (Reader in : inputStreamReaderList) {
|
||||||
try {
|
try {
|
||||||
BufferedReader br = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8), 512);
|
LineNumberReader br = new LineNumberReader(in);
|
||||||
String theWord;
|
String theWord;
|
||||||
do {
|
while ((theWord = br.readLine()) != null) {
|
||||||
theWord = br.readLine();
|
if (theWord.trim().length() == 0 || theWord.trim().charAt(0) == '#') continue;
|
||||||
if (theWord != null && !"".equals(theWord.trim())) {
|
singleton._MainDict.fillSegment(theWord.trim().toLowerCase().toCharArray());
|
||||||
singleton._MainDict.fillSegment(theWord.trim().toLowerCase().toCharArray());
|
}
|
||||||
}
|
|
||||||
} while (theWord != null);
|
|
||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) {
|
||||||
System.err.println("Other Dictionary loading exception.");
|
System.err.println("Other Dictionary loading exception.");
|
||||||
ioe.printStackTrace();
|
ioe.printStackTrace();
|
||||||
} finally {
|
} finally {
|
||||||
try {
|
try {
|
||||||
if (is != null) {
|
if (in != null) {
|
||||||
is.close();
|
in.close();
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|
Loading…
Reference in New Issue