From 47439fa94b9ace4707ba252b29ef535adb6c1025 Mon Sep 17 00:00:00 2001 From: Magese Date: Fri, 31 Dec 2021 17:31:28 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B3=A8=E9=87=8A=E6=A0=BC=E5=BC=8F=E5=8C=96?= =?UTF-8?q?=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/wltea/analyzer/core/IKArbitrator.java | 48 +++++++++---------- 1 file changed, 23 insertions(+), 25 deletions(-) diff --git a/src/main/java/org/wltea/analyzer/core/IKArbitrator.java b/src/main/java/org/wltea/analyzer/core/IKArbitrator.java index 999b17e..3dd9034 100644 --- a/src/main/java/org/wltea/analyzer/core/IKArbitrator.java +++ b/src/main/java/org/wltea/analyzer/core/IKArbitrator.java @@ -35,9 +35,7 @@ import java.util.TreeSet; */ class IKArbitrator { - IKArbitrator() { - - } + IKArbitrator() {} /** * 分词歧义处理 @@ -52,20 +50,20 @@ class IKArbitrator { LexemePath crossPath = new LexemePath(); while (orgLexeme != null) { if (!crossPath.addCrossLexeme(orgLexeme)) { - //找到与crossPath不相交的下一个crossPath + // 找到与crossPath不相交的下一个crossPath if (crossPath.size() == 1 || !useSmart) { - //crossPath没有歧义 或者 不做歧义处理 - //直接输出当前crossPath + // crossPath没有歧义 或者 不做歧义处理 + // 直接输出当前crossPath context.addLexemePath(crossPath); } else { - //对当前的crossPath进行歧义处理 + // 对当前的crossPath进行歧义处理 QuickSortSet.Cell headCell = crossPath.getHead(); LexemePath judgeResult = this.judge(headCell); - //输出歧义处理结果judgeResult + // 输出歧义处理结果judgeResult context.addLexemePath(judgeResult); } - //把orgLexeme加入新的crossPath中 + // 把orgLexeme加入新的crossPath中 crossPath = new LexemePath(); crossPath.addCrossLexeme(orgLexeme); } @@ -73,16 +71,16 @@ class IKArbitrator { } - //处理最后的path + // 处理最后的path if (crossPath.size() == 1 || !useSmart) { - //crossPath没有歧义 或者 不做歧义处理 - //直接输出当前crossPath + // crossPath没有歧义 或者 不做歧义处理 + // 直接输出当前crossPath context.addLexemePath(crossPath); } else { - //对当前的crossPath进行歧义处理 + // 对当前的crossPath进行歧义处理 QuickSortSet.Cell headCell = crossPath.getHead(); LexemePath judgeResult = this.judge(headCell); - //输出歧义处理结果judgeResult + // 输出歧义处理结果judgeResult context.addLexemePath(judgeResult); } } @@ -93,29 +91,29 @@ class IKArbitrator { * @param lexemeCell 歧义路径链表头 */ private LexemePath judge(QuickSortSet.Cell lexemeCell) { - //候选路径集合 + // 候选路径集合 TreeSet pathOptions = new TreeSet<>(); - //候选结果路径 + // 候选结果路径 LexemePath option = new LexemePath(); - //对crossPath进行一次遍历,同时返回本次遍历中有冲突的Lexeme栈 + // 对crossPath进行一次遍历,同时返回本次遍历中有冲突的Lexeme栈 Stack lexemeStack = this.forwardPath(lexemeCell, option); - //当前词元链并非最理想的,加入候选路径集合 + // 当前词元链并非最理想的,加入候选路径集合 pathOptions.add(option.copy()); - //存在歧义词,处理 + // 存在歧义词,处理 QuickSortSet.Cell c; while (!lexemeStack.isEmpty()) { c = lexemeStack.pop(); - //回滚词元链 + // 回滚词元链 this.backPath(c.getLexeme(), option); - //从歧义词位置开始,递归,生成可选方案 + // 从歧义词位置开始,递归,生成可选方案 this.forwardPath(c, option); pathOptions.add(option.copy()); } - //返回集合中的最优方案 + // 返回集合中的最优方案 return pathOptions.first(); } @@ -124,13 +122,13 @@ class IKArbitrator { * 向前遍历,添加词元,构造一个无歧义词元组合 */ private Stack forwardPath(QuickSortSet.Cell lexemeCell, LexemePath option) { - //发生冲突的Lexeme栈 + // 发生冲突的Lexeme栈 Stack conflictStack = new Stack<>(); QuickSortSet.Cell c = lexemeCell; - //迭代遍历Lexeme链表 + // 迭代遍历Lexeme链表 while (c != null && c.getLexeme() != null) { if (!option.addNotCrossLexeme(c.getLexeme())) { - //词元交叉,添加失败则加入lexemeStack栈 + // 词元交叉,添加失败则加入lexemeStack栈 conflictStack.push(c); } c = c.getNext();