26
26
27
27
import java .io .IOException ;
28
28
import java .io .Reader ;
29
- import java .util .HashMap ;
30
- import java .util .HashSet ;
31
- import java .util .LinkedList ;
32
- import java .util .Map ;
33
- import java .util .Set ;
29
+ import java .util .*;
34
30
35
31
import org .wltea .analyzer .cfg .Configuration ;
36
32
import org .wltea .analyzer .dic .Dictionary ;
@@ -72,7 +68,7 @@ class AnalyzeContext {
72
68
//LexemePath位置索引表
73
69
private Map <Integer , LexemePath > pathMap ;
74
70
//最终分词结果集
75
- private LinkedList <Lexeme > results ;
71
+ private TreeSet <Lexeme > results ;
76
72
//分词器配置项
77
73
private Configuration cfg ;
78
74
@@ -83,7 +79,7 @@ public AnalyzeContext(Configuration configuration){
83
79
this .buffLocker = new HashSet <String >();
84
80
this .orgLexemes = new QuickSortSet ();
85
81
this .pathMap = new HashMap <Integer , LexemePath >();
86
- this .results = new LinkedList <Lexeme >();
82
+ this .results = new TreeSet <Lexeme >();
87
83
}
88
84
89
85
int getCursor (){
@@ -361,7 +357,7 @@ private void compound(Lexeme result){
361
357
if (!this .results .isEmpty ()){
362
358
363
359
if (Lexeme .TYPE_ARABIC == result .getLexemeType ()){
364
- Lexeme nextLexeme = this .results .peekFirst ();
360
+ Lexeme nextLexeme = this .results .first ();
365
361
boolean appendOk = false ;
366
362
if (Lexeme .TYPE_CNUM == nextLexeme .getLexemeType ()){
367
363
//合并英文数词+中文数词
@@ -378,7 +374,7 @@ private void compound(Lexeme result){
378
374
379
375
//可能存在第二轮合并
380
376
if (Lexeme .TYPE_CNUM == result .getLexemeType () && !this .results .isEmpty ()){
381
- Lexeme nextLexeme = this .results .peekFirst ();
377
+ Lexeme nextLexeme = this .results .first ();
382
378
boolean appendOk = false ;
383
379
if (Lexeme .TYPE_COUNT == nextLexeme .getLexemeType ()){
384
380
//合并中文数词+中文量词
0 commit comments