本文整理汇总了Java中org.wltea.analyzer.dic.Dictionary类的典型用法代码示例。如果您正苦于以下问题:Java Dictionary类的具体用法?Java Dictionary怎么用?Java Dictionary使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Dictionary类属于org.wltea.analyzer.dic包,在下文中一共展示了Dictionary类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getNextLexeme
import org.wltea.analyzer.dic.Dictionary; //导入依赖的package包/类
/**
* 返回lexeme
*
* 同时处理合并
* @return
*/
Lexeme getNextLexeme(){
//从结果集取出,并移除第一个Lexme
Lexeme result = this.results.pollFirst();
while(result != null){
//数量词合并
this.compound(result);
if(Dictionary.getSingleton().isStopWord(this.segmentBuff , result.getBegin() , result.getLength())){
//是停止词继续取列表的下一个
result = this.results.pollFirst();
}else{
//不是停止词, 生成lexeme的词元文本,输出
result.setLexemeText(String.valueOf(segmentBuff , result.getBegin() , result.getLength()));
break;
}
}
return result;
}
示例2: getIKAnalyzerResult
import org.wltea.analyzer.dic.Dictionary; //导入依赖的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;
}
示例3: init
import org.wltea.analyzer.dic.Dictionary; //导入依赖的package包/类
/**
* 初始化
*/
private void init(){
//初始化词典单例
Dictionary.initial(this.cfg);
//初始化分词上下文
this.context = new AnalyzeContext(this.cfg);
//加载子分词器
this.segmenters = this.loadSegmenters();
//加载歧义裁决器
this.arbitrator = new IKArbitrator();
}
示例4: Configuration
import org.wltea.analyzer.dic.Dictionary; //导入依赖的package包/类
@Inject
public Configuration(Environment env,Settings settings) {
this.environment = env;
this.settings=settings;
this.useSmart = settings.get("use_smart", "false").equals("true");
this.enableLowercase = settings.get("enable_lowercase", "true").equals("true");
this.enableRemoteDict = settings.get("enable_remote_dict", "true").equals("true");
Dictionary.initial(this);
}