Skip to content

Commit

Permalink
bug fix for issue 662
Browse files Browse the repository at this point in the history
this.result 从 LinkedList 改成 TreeSet,修复 issue 662 问题,
infinilabs#662
  • Loading branch information
yanghanxy authored Nov 19, 2020
1 parent 125ac3c commit c8dacc3
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/main/java/org/wltea/analyzer/core/AnalyzeContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.TreeSet;
import java.util.Map;
import java.util.Set;

Expand Down Expand Up @@ -72,7 +73,7 @@ class AnalyzeContext {
//LexemePath位置索引表
private Map<Integer , LexemePath> pathMap;
//最终分词结果集
private LinkedList<Lexeme> results;
private TreeSet<Lexeme> results;
//分词器配置项
private Configuration cfg;

Expand All @@ -83,7 +84,7 @@ public AnalyzeContext(Configuration configuration){
this.buffLocker = new HashSet<String>();
this.orgLexemes = new QuickSortSet();
this.pathMap = new HashMap<Integer , LexemePath>();
this.results = new LinkedList<Lexeme>();
this.results = new TreeSet<Lexeme>();
}

int getCursor(){
Expand Down Expand Up @@ -361,7 +362,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()){
//合并英文数词+中文数词
Expand All @@ -378,7 +379,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()){
//合并中文数词+中文量词
Expand Down

0 comments on commit c8dacc3

Please sign in to comment.