注释格式化;
This commit is contained in:
parent
c938bf1f2b
commit
47439fa94b
|
@ -35,9 +35,7 @@ import java.util.TreeSet;
|
||||||
*/
|
*/
|
||||||
class IKArbitrator {
|
class IKArbitrator {
|
||||||
|
|
||||||
IKArbitrator() {
|
IKArbitrator() {}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 分词歧义处理
|
* 分词歧义处理
|
||||||
|
@ -52,20 +50,20 @@ class IKArbitrator {
|
||||||
LexemePath crossPath = new LexemePath();
|
LexemePath crossPath = new LexemePath();
|
||||||
while (orgLexeme != null) {
|
while (orgLexeme != null) {
|
||||||
if (!crossPath.addCrossLexeme(orgLexeme)) {
|
if (!crossPath.addCrossLexeme(orgLexeme)) {
|
||||||
//找到与crossPath不相交的下一个crossPath
|
// 找到与crossPath不相交的下一个crossPath
|
||||||
if (crossPath.size() == 1 || !useSmart) {
|
if (crossPath.size() == 1 || !useSmart) {
|
||||||
//crossPath没有歧义 或者 不做歧义处理
|
// crossPath没有歧义 或者 不做歧义处理
|
||||||
//直接输出当前crossPath
|
// 直接输出当前crossPath
|
||||||
context.addLexemePath(crossPath);
|
context.addLexemePath(crossPath);
|
||||||
} else {
|
} else {
|
||||||
//对当前的crossPath进行歧义处理
|
// 对当前的crossPath进行歧义处理
|
||||||
QuickSortSet.Cell headCell = crossPath.getHead();
|
QuickSortSet.Cell headCell = crossPath.getHead();
|
||||||
LexemePath judgeResult = this.judge(headCell);
|
LexemePath judgeResult = this.judge(headCell);
|
||||||
//输出歧义处理结果judgeResult
|
// 输出歧义处理结果judgeResult
|
||||||
context.addLexemePath(judgeResult);
|
context.addLexemePath(judgeResult);
|
||||||
}
|
}
|
||||||
|
|
||||||
//把orgLexeme加入新的crossPath中
|
// 把orgLexeme加入新的crossPath中
|
||||||
crossPath = new LexemePath();
|
crossPath = new LexemePath();
|
||||||
crossPath.addCrossLexeme(orgLexeme);
|
crossPath.addCrossLexeme(orgLexeme);
|
||||||
}
|
}
|
||||||
|
@ -73,16 +71,16 @@ class IKArbitrator {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//处理最后的path
|
// 处理最后的path
|
||||||
if (crossPath.size() == 1 || !useSmart) {
|
if (crossPath.size() == 1 || !useSmart) {
|
||||||
//crossPath没有歧义 或者 不做歧义处理
|
// crossPath没有歧义 或者 不做歧义处理
|
||||||
//直接输出当前crossPath
|
// 直接输出当前crossPath
|
||||||
context.addLexemePath(crossPath);
|
context.addLexemePath(crossPath);
|
||||||
} else {
|
} else {
|
||||||
//对当前的crossPath进行歧义处理
|
// 对当前的crossPath进行歧义处理
|
||||||
QuickSortSet.Cell headCell = crossPath.getHead();
|
QuickSortSet.Cell headCell = crossPath.getHead();
|
||||||
LexemePath judgeResult = this.judge(headCell);
|
LexemePath judgeResult = this.judge(headCell);
|
||||||
//输出歧义处理结果judgeResult
|
// 输出歧义处理结果judgeResult
|
||||||
context.addLexemePath(judgeResult);
|
context.addLexemePath(judgeResult);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -93,29 +91,29 @@ class IKArbitrator {
|
||||||
* @param lexemeCell 歧义路径链表头
|
* @param lexemeCell 歧义路径链表头
|
||||||
*/
|
*/
|
||||||
private LexemePath judge(QuickSortSet.Cell lexemeCell) {
|
private LexemePath judge(QuickSortSet.Cell lexemeCell) {
|
||||||
//候选路径集合
|
// 候选路径集合
|
||||||
TreeSet<LexemePath> pathOptions = new TreeSet<>();
|
TreeSet<LexemePath> pathOptions = new TreeSet<>();
|
||||||
//候选结果路径
|
// 候选结果路径
|
||||||
LexemePath option = new LexemePath();
|
LexemePath option = new LexemePath();
|
||||||
|
|
||||||
//对crossPath进行一次遍历,同时返回本次遍历中有冲突的Lexeme栈
|
// 对crossPath进行一次遍历,同时返回本次遍历中有冲突的Lexeme栈
|
||||||
Stack<QuickSortSet.Cell> lexemeStack = this.forwardPath(lexemeCell, option);
|
Stack<QuickSortSet.Cell> lexemeStack = this.forwardPath(lexemeCell, option);
|
||||||
|
|
||||||
//当前词元链并非最理想的,加入候选路径集合
|
// 当前词元链并非最理想的,加入候选路径集合
|
||||||
pathOptions.add(option.copy());
|
pathOptions.add(option.copy());
|
||||||
|
|
||||||
//存在歧义词,处理
|
// 存在歧义词,处理
|
||||||
QuickSortSet.Cell c;
|
QuickSortSet.Cell c;
|
||||||
while (!lexemeStack.isEmpty()) {
|
while (!lexemeStack.isEmpty()) {
|
||||||
c = lexemeStack.pop();
|
c = lexemeStack.pop();
|
||||||
//回滚词元链
|
// 回滚词元链
|
||||||
this.backPath(c.getLexeme(), option);
|
this.backPath(c.getLexeme(), option);
|
||||||
//从歧义词位置开始,递归,生成可选方案
|
// 从歧义词位置开始,递归,生成可选方案
|
||||||
this.forwardPath(c, option);
|
this.forwardPath(c, option);
|
||||||
pathOptions.add(option.copy());
|
pathOptions.add(option.copy());
|
||||||
}
|
}
|
||||||
|
|
||||||
//返回集合中的最优方案
|
// 返回集合中的最优方案
|
||||||
return pathOptions.first();
|
return pathOptions.first();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -124,13 +122,13 @@ class IKArbitrator {
|
||||||
* 向前遍历,添加词元,构造一个无歧义词元组合
|
* 向前遍历,添加词元,构造一个无歧义词元组合
|
||||||
*/
|
*/
|
||||||
private Stack<QuickSortSet.Cell> forwardPath(QuickSortSet.Cell lexemeCell, LexemePath option) {
|
private Stack<QuickSortSet.Cell> forwardPath(QuickSortSet.Cell lexemeCell, LexemePath option) {
|
||||||
//发生冲突的Lexeme栈
|
// 发生冲突的Lexeme栈
|
||||||
Stack<QuickSortSet.Cell> conflictStack = new Stack<>();
|
Stack<QuickSortSet.Cell> conflictStack = new Stack<>();
|
||||||
QuickSortSet.Cell c = lexemeCell;
|
QuickSortSet.Cell c = lexemeCell;
|
||||||
//迭代遍历Lexeme链表
|
// 迭代遍历Lexeme链表
|
||||||
while (c != null && c.getLexeme() != null) {
|
while (c != null && c.getLexeme() != null) {
|
||||||
if (!option.addNotCrossLexeme(c.getLexeme())) {
|
if (!option.addNotCrossLexeme(c.getLexeme())) {
|
||||||
//词元交叉,添加失败则加入lexemeStack栈
|
// 词元交叉,添加失败则加入lexemeStack栈
|
||||||
conflictStack.push(c);
|
conflictStack.push(c);
|
||||||
}
|
}
|
||||||
c = c.getNext();
|
c = c.getNext();
|
||||||
|
|
Loading…
Reference in New Issue