Merging collapsible if statements increases the code's readability.
This commit is contained in:
parent
71b5211781
commit
5fb03d2751
@ -127,14 +127,12 @@ class CN_QuantifierSegmenter implements ISegmenter{
|
||||
}
|
||||
|
||||
//缓冲区已经用完,还有尚未输出的数词
|
||||
if(context.isBufferConsumed()){
|
||||
if(nStart != -1 && nEnd != -1){
|
||||
//输出数词
|
||||
outputNumLexeme(context);
|
||||
//重置头尾指针
|
||||
nStart = -1;
|
||||
nEnd = -1;
|
||||
}
|
||||
if(context.isBufferConsumed() && (nStart != -1 && nEnd != -1)){
|
||||
//输出数词
|
||||
outputNumLexeme(context);
|
||||
//重置头尾指针
|
||||
nStart = -1;
|
||||
nEnd = -1;
|
||||
}
|
||||
}
|
||||
|
||||
@ -216,10 +214,9 @@ class CN_QuantifierSegmenter implements ISegmenter{
|
||||
//找到一个相邻的数词
|
||||
if(!context.getOrgLexemes().isEmpty()){
|
||||
Lexeme l = context.getOrgLexemes().peekLast();
|
||||
if(Lexeme.TYPE_CNUM == l.getLexemeType() || Lexeme.TYPE_ARABIC == l.getLexemeType()){
|
||||
if(l.getBegin() + l.getLength() == context.getCursor()){
|
||||
return true;
|
||||
}
|
||||
if((Lexeme.TYPE_CNUM == l.getLexemeType() || Lexeme.TYPE_ARABIC == l.getLexemeType())
|
||||
&& (l.getBegin() + l.getLength() == context.getCursor())){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -155,14 +155,12 @@ class LetterSegmenter implements ISegmenter {
|
||||
}
|
||||
|
||||
//判断缓冲区是否已经读完
|
||||
if(context.isBufferConsumed()){
|
||||
if(this.start != -1 && this.end != -1){
|
||||
//缓冲以读完,输出词元
|
||||
Lexeme newLexeme = new Lexeme(context.getBufferOffset() , this.start , this.end - this.start + 1 , Lexeme.TYPE_LETTER);
|
||||
context.addLexeme(newLexeme);
|
||||
this.start = -1;
|
||||
this.end = -1;
|
||||
}
|
||||
if(context.isBufferConsumed() && (this.start != -1 && this.end != -1)){
|
||||
//缓冲以读完,输出词元
|
||||
Lexeme newLexeme = new Lexeme(context.getBufferOffset() , this.start , this.end - this.start + 1 , Lexeme.TYPE_LETTER);
|
||||
context.addLexeme(newLexeme);
|
||||
this.start = -1;
|
||||
this.end = -1;
|
||||
}
|
||||
|
||||
//判断是否锁定缓冲区
|
||||
@ -203,14 +201,12 @@ class LetterSegmenter implements ISegmenter {
|
||||
}
|
||||
|
||||
//判断缓冲区是否已经读完
|
||||
if(context.isBufferConsumed()){
|
||||
if(this.englishStart != -1 && this.englishEnd != -1){
|
||||
//缓冲以读完,输出词元
|
||||
Lexeme newLexeme = new Lexeme(context.getBufferOffset() , this.englishStart , this.englishEnd - this.englishStart + 1 , Lexeme.TYPE_ENGLISH);
|
||||
context.addLexeme(newLexeme);
|
||||
this.englishStart = -1;
|
||||
this.englishEnd= -1;
|
||||
}
|
||||
if(context.isBufferConsumed() && (this.englishStart != -1 && this.englishEnd != -1)){
|
||||
//缓冲以读完,输出词元
|
||||
Lexeme newLexeme = new Lexeme(context.getBufferOffset() , this.englishStart , this.englishEnd - this.englishStart + 1 , Lexeme.TYPE_ENGLISH);
|
||||
context.addLexeme(newLexeme);
|
||||
this.englishStart = -1;
|
||||
this.englishEnd= -1;
|
||||
}
|
||||
|
||||
//判断是否锁定缓冲区
|
||||
@ -254,14 +250,12 @@ class LetterSegmenter implements ISegmenter {
|
||||
}
|
||||
|
||||
//判断缓冲区是否已经读完
|
||||
if(context.isBufferConsumed()){
|
||||
if(this.arabicStart != -1 && this.arabicEnd != -1){
|
||||
//生成已切分的词元
|
||||
Lexeme newLexeme = new Lexeme(context.getBufferOffset() , this.arabicStart , this.arabicEnd - this.arabicStart + 1 , Lexeme.TYPE_ARABIC);
|
||||
context.addLexeme(newLexeme);
|
||||
this.arabicStart = -1;
|
||||
this.arabicEnd = -1;
|
||||
}
|
||||
if(context.isBufferConsumed() && (this.arabicStart != -1 && this.arabicEnd != -1)){
|
||||
//生成已切分的词元
|
||||
Lexeme newLexeme = new Lexeme(context.getBufferOffset() , this.arabicStart , this.arabicEnd - this.arabicStart + 1 , Lexeme.TYPE_ARABIC);
|
||||
context.addLexeme(newLexeme);
|
||||
this.arabicStart = -1;
|
||||
this.arabicEnd = -1;
|
||||
}
|
||||
|
||||
//判断是否锁定缓冲区
|
||||
|
Loading…
x
Reference in New Issue
Block a user