本文整理汇总了Java中org.wltea.analyzer.cfg.DefaultConfig.getInstance方法的典型用法代码示例。如果您正苦于以下问题:Java DefaultConfig.getInstance方法的具体用法?Java DefaultConfig.getInstance怎么用?Java DefaultConfig.getInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.wltea.analyzer.cfg.DefaultConfig
的用法示例。
在下文中一共展示了DefaultConfig.getInstance方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getIKAnalyzerResult
import org.wltea.analyzer.cfg.DefaultConfig; //导入方法依赖的package包/类
public static List<String> getIKAnalyzerResult(String originTxt, boolean useSmart, Collection<String> words)throws Exception{
if(originTxt == null || originTxt.trim().equals("")){
return null;
}
//如下代码为动态增加新词的办法,可以完善成动态加载的接口
if(null != words && words.size() != 0){
Configuration cfg = DefaultConfig.getInstance();
Dictionary dic = Dictionary.initial(cfg);
dic = Dictionary.getSingleton();
dic.addWords(words);
}
InputStream in = new ByteArrayInputStream(originTxt.getBytes());
IKSegmenter ik = new IKSegmenter(new InputStreamReader(in), useSmart);
List<String> result = new ArrayList<String>();
Lexeme t = null;
while( (t=ik.next()) != null){
result.add(t.getLexemeText());
}
return result;
}
示例2: createComponents
import org.wltea.analyzer.cfg.DefaultConfig; //导入方法依赖的package包/类
@Override
protected TokenStreamComponents createComponents(String fieldName, Reader reader) {
Tokenizer token = new IKTokenizer(reader, useSmart);
Map<String, String> paramsMap = new HashMap<String, String>();
Configuration cfg = DefaultConfig.getInstance();
paramsMap.put("luceneMatchVersion", luceneMatchVersion.toString());
paramsMap.put("synonyms", cfg.getExtSynonymDictionarys().get(0));
paramsMap.put("ignoreCase", "true");
SynonymFilterFactory factory = new SynonymFilterFactory(paramsMap);
ResourceLoader loader = new ClasspathResourceLoader();
try {
factory.inform(loader);
} catch (IOException e) {
e.printStackTrace();
}
return new TokenStreamComponents(token, factory.create(token));
}
示例3: IKSegmenter
import org.wltea.analyzer.cfg.DefaultConfig; //导入方法依赖的package包/类
/**
* IK分词器构造函数
* @param input
* @param useSmart 为true,使用智能分词策略
*
* 非智能分词:细粒度输出所有可能的切分结果
* 智能分词: 合并数词和量词,对分词结果进行歧义判断
*/
public IKSegmenter(Reader input , boolean useSmart){
this.input = input;
this.cfg = DefaultConfig.getInstance();
this.cfg.setUseSmart(useSmart);
this.init();
}