Merging collapsible if statements increases the code's readability.

This commit is contained in:
Ayman Abdel Ghany 2016-01-21 19:13:41 +02:00
parent 71b5211781
commit 5fb03d2751
2 changed files with 27 additions and 36 deletions

View File

@ -127,14 +127,12 @@ class CN_QuantifierSegmenter implements ISegmenter{
} }
//缓冲区已经用完还有尚未输出的数词 //缓冲区已经用完还有尚未输出的数词
if(context.isBufferConsumed()){ if(context.isBufferConsumed() && (nStart != -1 && nEnd != -1)){
if(nStart != -1 && nEnd != -1){ //输出数词
//输出数词 outputNumLexeme(context);
outputNumLexeme(context); //重置头尾指针
//重置头尾指针 nStart = -1;
nStart = -1; nEnd = -1;
nEnd = -1;
}
} }
} }
@ -216,10 +214,9 @@ class CN_QuantifierSegmenter implements ISegmenter{
//找到一个相邻的数词 //找到一个相邻的数词
if(!context.getOrgLexemes().isEmpty()){ if(!context.getOrgLexemes().isEmpty()){
Lexeme l = context.getOrgLexemes().peekLast(); Lexeme l = context.getOrgLexemes().peekLast();
if(Lexeme.TYPE_CNUM == l.getLexemeType() || Lexeme.TYPE_ARABIC == l.getLexemeType()){ if((Lexeme.TYPE_CNUM == l.getLexemeType() || Lexeme.TYPE_ARABIC == l.getLexemeType())
if(l.getBegin() + l.getLength() == context.getCursor()){ && (l.getBegin() + l.getLength() == context.getCursor())){
return true; return true;
}
} }
} }
} }

View File

@ -155,14 +155,12 @@ class LetterSegmenter implements ISegmenter {
} }
//判断缓冲区是否已经读完 //判断缓冲区是否已经读完
if(context.isBufferConsumed()){ if(context.isBufferConsumed() && (this.start != -1 && this.end != -1)){
if(this.start != -1 && this.end != -1){ //缓冲以读完输出词元
//缓冲以读完输出词元 Lexeme newLexeme = new Lexeme(context.getBufferOffset() , this.start , this.end - this.start + 1 , Lexeme.TYPE_LETTER);
Lexeme newLexeme = new Lexeme(context.getBufferOffset() , this.start , this.end - this.start + 1 , Lexeme.TYPE_LETTER); context.addLexeme(newLexeme);
context.addLexeme(newLexeme); this.start = -1;
this.start = -1; this.end = -1;
this.end = -1;
}
} }
//判断是否锁定缓冲区 //判断是否锁定缓冲区
@ -203,14 +201,12 @@ class LetterSegmenter implements ISegmenter {
} }
//判断缓冲区是否已经读完 //判断缓冲区是否已经读完
if(context.isBufferConsumed()){ if(context.isBufferConsumed() && (this.englishStart != -1 && this.englishEnd != -1)){
if(this.englishStart != -1 && this.englishEnd != -1){ //缓冲以读完输出词元
//缓冲以读完输出词元 Lexeme newLexeme = new Lexeme(context.getBufferOffset() , this.englishStart , this.englishEnd - this.englishStart + 1 , Lexeme.TYPE_ENGLISH);
Lexeme newLexeme = new Lexeme(context.getBufferOffset() , this.englishStart , this.englishEnd - this.englishStart + 1 , Lexeme.TYPE_ENGLISH); context.addLexeme(newLexeme);
context.addLexeme(newLexeme); this.englishStart = -1;
this.englishStart = -1; this.englishEnd= -1;
this.englishEnd= -1;
}
} }
//判断是否锁定缓冲区 //判断是否锁定缓冲区
@ -254,14 +250,12 @@ class LetterSegmenter implements ISegmenter {
} }
//判断缓冲区是否已经读完 //判断缓冲区是否已经读完
if(context.isBufferConsumed()){ if(context.isBufferConsumed() && (this.arabicStart != -1 && this.arabicEnd != -1)){
if(this.arabicStart != -1 && this.arabicEnd != -1){ //生成已切分的词元
//生成已切分的词元 Lexeme newLexeme = new Lexeme(context.getBufferOffset() , this.arabicStart , this.arabicEnd - this.arabicStart + 1 , Lexeme.TYPE_ARABIC);
Lexeme newLexeme = new Lexeme(context.getBufferOffset() , this.arabicStart , this.arabicEnd - this.arabicStart + 1 , Lexeme.TYPE_ARABIC); context.addLexeme(newLexeme);
context.addLexeme(newLexeme); this.arabicStart = -1;
this.arabicStart = -1; this.arabicEnd = -1;
this.arabicEnd = -1;
}
} }
//判断是否锁定缓冲区 //判断是否锁定缓冲区