|
|
|
@ -32,6 +32,8 @@ import java.io.InputStreamReader;
|
|
|
|
|
import java.util.Collection;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
import org.springframework.core.io.ClassPathResource;
|
|
|
|
|
|
|
|
|
|
import com.luoo.music.ik.cfg.Configuration;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -195,13 +197,8 @@ public class Dictionary {
|
|
|
|
|
//建立一个主词典实例
|
|
|
|
|
_MainDict = new DictSegment((char)0);
|
|
|
|
|
//读取主词典文件
|
|
|
|
|
InputStream is = this.getClass().getClassLoader().getResourceAsStream(cfg.getMainDictionary());
|
|
|
|
|
if(is == null){
|
|
|
|
|
throw new RuntimeException("Main Dictionary not found!!!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
BufferedReader br = new BufferedReader(new InputStreamReader(is , "UTF-8"), 512);
|
|
|
|
|
try (InputStream is = new ClassPathResource(cfg.getMainDictionary()).getInputStream();
|
|
|
|
|
BufferedReader br = new BufferedReader(new InputStreamReader(is , "UTF-8"), 512);) {
|
|
|
|
|
String theWord = null;
|
|
|
|
|
do {
|
|
|
|
|
theWord = br.readLine();
|
|
|
|
@ -209,21 +206,10 @@ public class Dictionary {
|
|
|
|
|
_MainDict.fillSegment(theWord.trim().toLowerCase().toCharArray());
|
|
|
|
|
}
|
|
|
|
|
} while (theWord != null);
|
|
|
|
|
|
|
|
|
|
} catch (IOException ioe) {
|
|
|
|
|
System.err.println("Main Dictionary loading exception.");
|
|
|
|
|
ioe.printStackTrace();
|
|
|
|
|
|
|
|
|
|
}finally{
|
|
|
|
|
try {
|
|
|
|
|
if(is != null){
|
|
|
|
|
is.close();
|
|
|
|
|
is = null;
|
|
|
|
|
}
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
System.err.println("Main Dictionary loading exception.");
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//加载扩展词典
|
|
|
|
|
this.loadExtDict();
|
|
|
|
|
}
|
|
|
|
@ -235,17 +221,11 @@ public class Dictionary {
|
|
|
|
|
//加载扩展词典配置
|
|
|
|
|
List<String> extDictFiles = cfg.getExtDictionarys();
|
|
|
|
|
if(extDictFiles != null){
|
|
|
|
|
InputStream is = null;
|
|
|
|
|
for(String extDictName : extDictFiles){
|
|
|
|
|
//读取扩展词典文件
|
|
|
|
|
System.out.println("加载扩展词典:" + extDictName);
|
|
|
|
|
is = this.getClass().getClassLoader().getResourceAsStream(extDictName);
|
|
|
|
|
//如果找不到扩展的字典,则忽略
|
|
|
|
|
if(is == null){
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
BufferedReader br = new BufferedReader(new InputStreamReader(is , "UTF-8"), 512);
|
|
|
|
|
try (InputStream is = new ClassPathResource(extDictName).getInputStream();
|
|
|
|
|
BufferedReader br = new BufferedReader(new InputStreamReader(is , "UTF-8"), 512);) {
|
|
|
|
|
String theWord = null;
|
|
|
|
|
do {
|
|
|
|
|
theWord = br.readLine();
|
|
|
|
@ -255,24 +235,13 @@ public class Dictionary {
|
|
|
|
|
_MainDict.fillSegment(theWord.trim().toLowerCase().toCharArray());
|
|
|
|
|
}
|
|
|
|
|
} while (theWord != null);
|
|
|
|
|
|
|
|
|
|
} catch (IOException ioe) {
|
|
|
|
|
System.err.println("Extension Dictionary loading exception.");
|
|
|
|
|
ioe.printStackTrace();
|
|
|
|
|
|
|
|
|
|
}finally{
|
|
|
|
|
try {
|
|
|
|
|
if(is != null){
|
|
|
|
|
is.close();
|
|
|
|
|
is = null;
|
|
|
|
|
}
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
System.err.println("Extension Dictionary loading exception.");
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 加载用户扩展的停止词词典
|
|
|
|
@ -283,17 +252,11 @@ public class Dictionary {
|
|
|
|
|
//加载扩展停止词典
|
|
|
|
|
List<String> extStopWordDictFiles = cfg.getExtStopWordDictionarys();
|
|
|
|
|
if(extStopWordDictFiles != null){
|
|
|
|
|
InputStream is = null;
|
|
|
|
|
for(String extStopWordDictName : extStopWordDictFiles){
|
|
|
|
|
System.out.println("加载扩展停止词典:" + extStopWordDictName);
|
|
|
|
|
//读取扩展词典文件
|
|
|
|
|
is = this.getClass().getClassLoader().getResourceAsStream(extStopWordDictName);
|
|
|
|
|
//如果找不到扩展的字典,则忽略
|
|
|
|
|
if(is == null){
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
BufferedReader br = new BufferedReader(new InputStreamReader(is , "UTF-8"), 512);
|
|
|
|
|
try (InputStream is = new ClassPathResource(extStopWordDictName).getInputStream();
|
|
|
|
|
BufferedReader br = new BufferedReader(new InputStreamReader(is , "UTF-8"), 512);) {
|
|
|
|
|
String theWord = null;
|
|
|
|
|
do {
|
|
|
|
|
theWord = br.readLine();
|
|
|
|
@ -303,24 +266,13 @@ public class Dictionary {
|
|
|
|
|
_StopWordDict.fillSegment(theWord.trim().toLowerCase().toCharArray());
|
|
|
|
|
}
|
|
|
|
|
} while (theWord != null);
|
|
|
|
|
|
|
|
|
|
} catch (IOException ioe) {
|
|
|
|
|
System.err.println("Extension Stop word Dictionary loading exception.");
|
|
|
|
|
ioe.printStackTrace();
|
|
|
|
|
|
|
|
|
|
}finally{
|
|
|
|
|
try {
|
|
|
|
|
if(is != null){
|
|
|
|
|
is.close();
|
|
|
|
|
is = null;
|
|
|
|
|
}
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
System.err.println("Extension Stop word Dictionary loading exception.");
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 加载量词词典
|
|
|
|
@ -329,12 +281,8 @@ public class Dictionary {
|
|
|
|
|
//建立一个量词典实例
|
|
|
|
|
_QuantifierDict = new DictSegment((char)0);
|
|
|
|
|
//读取量词词典文件
|
|
|
|
|
InputStream is = this.getClass().getClassLoader().getResourceAsStream(cfg.getQuantifierDicionary());
|
|
|
|
|
if(is == null){
|
|
|
|
|
throw new RuntimeException("Quantifier Dictionary not found!!!");
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
BufferedReader br = new BufferedReader(new InputStreamReader(is , "UTF-8"), 512);
|
|
|
|
|
try (InputStream is = new ClassPathResource(cfg.getQuantifierDicionary()).getInputStream();
|
|
|
|
|
BufferedReader br = new BufferedReader(new InputStreamReader(is , "UTF-8"), 512);) {
|
|
|
|
|
String theWord = null;
|
|
|
|
|
do {
|
|
|
|
|
theWord = br.readLine();
|
|
|
|
@ -342,21 +290,10 @@ public class Dictionary {
|
|
|
|
|
_QuantifierDict.fillSegment(theWord.trim().toLowerCase().toCharArray());
|
|
|
|
|
}
|
|
|
|
|
} while (theWord != null);
|
|
|
|
|
|
|
|
|
|
} catch (IOException ioe) {
|
|
|
|
|
System.err.println("Quantifier Dictionary loading exception.");
|
|
|
|
|
ioe.printStackTrace();
|
|
|
|
|
|
|
|
|
|
}finally{
|
|
|
|
|
try {
|
|
|
|
|
if(is != null){
|
|
|
|
|
is.close();
|
|
|
|
|
is = null;
|
|
|
|
|
}
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
System.err.println("Quantifier Dictionary loading exception.");
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|