From 00a39bbc98637f22edbfa706e575ee65bb3733ae Mon Sep 17 00:00:00 2001 From: livelxw Date: Wed, 9 Dec 2020 15:36:51 +0800 Subject: [PATCH] Merge PR medcl/elasticsearch-analysis-ik#835 --- .../org/wltea/analyzer/core/AnalyzeContext.java | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/wltea/analyzer/core/AnalyzeContext.java b/src/main/java/org/wltea/analyzer/core/AnalyzeContext.java index 5bf1ac90..8f864b80 100644 --- a/src/main/java/org/wltea/analyzer/core/AnalyzeContext.java +++ b/src/main/java/org/wltea/analyzer/core/AnalyzeContext.java @@ -26,11 +26,7 @@ import java.io.IOException; import java.io.Reader; -import java.util.HashMap; -import java.util.HashSet; -import java.util.LinkedList; -import java.util.Map; -import java.util.Set; +import java.util.*; import org.wltea.analyzer.cfg.Configuration; import org.wltea.analyzer.dic.Dictionary; @@ -72,7 +68,7 @@ class AnalyzeContext { //LexemePath位置索引表 private Map pathMap; //最终分词结果集 - private LinkedList results; + private TreeSet results; //分词器配置项 private Configuration cfg; @@ -83,7 +79,7 @@ public AnalyzeContext(Configuration configuration){ this.buffLocker = new HashSet(); this.orgLexemes = new QuickSortSet(); this.pathMap = new HashMap(); - this.results = new LinkedList(); + this.results = new TreeSet(); } int getCursor(){ @@ -361,7 +357,7 @@ private void compound(Lexeme result){ if(!this.results.isEmpty()){ if(Lexeme.TYPE_ARABIC == result.getLexemeType()){ - Lexeme nextLexeme = this.results.peekFirst(); + Lexeme nextLexeme = this.results.first(); boolean appendOk = false; if(Lexeme.TYPE_CNUM == nextLexeme.getLexemeType()){ //合并英文数词+中文数词 @@ -378,7 +374,7 @@ private void compound(Lexeme result){ //可能存在第二轮合并 if(Lexeme.TYPE_CNUM == result.getLexemeType() && !this.results.isEmpty()){ - Lexeme nextLexeme = this.results.peekFirst(); + Lexeme nextLexeme = this.results.first(); boolean appendOk = false; if(Lexeme.TYPE_COUNT == nextLexeme.getLexemeType()){ //合并中文数词+中文量词