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,8 +127,7 @@ class CN_QuantifierSegmenter implements ISegmenter{
} }
//缓冲区已经用完还有尚未输出的数词 //缓冲区已经用完还有尚未输出的数词
if(context.isBufferConsumed()){ if(context.isBufferConsumed() && (nStart != -1 && nEnd != -1)){
if(nStart != -1 && nEnd != -1){
//输出数词 //输出数词
outputNumLexeme(context); outputNumLexeme(context);
//重置头尾指针 //重置头尾指针
@ -136,7 +135,6 @@ class CN_QuantifierSegmenter implements ISegmenter{
nEnd = -1; nEnd = -1;
} }
} }
}
/** /**
* 处理中文量词 * 处理中文量词
@ -216,13 +214,12 @@ 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;
} }
} }
} }
}
return false; return false;
} }

View File

@ -155,15 +155,13 @@ 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;
} }
}
//判断是否锁定缓冲区 //判断是否锁定缓冲区
if(this.start == -1 && this.end == -1){ if(this.start == -1 && this.end == -1){
@ -203,15 +201,13 @@ 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;
} }
}
//判断是否锁定缓冲区 //判断是否锁定缓冲区
if(this.englishStart == -1 && this.englishEnd == -1){ if(this.englishStart == -1 && this.englishEnd == -1){
@ -254,15 +250,13 @@ 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;
} }
}
//判断是否锁定缓冲区 //判断是否锁定缓冲区
if(this.arabicStart == -1 && this.arabicEnd == -1){ if(this.arabicStart == -1 && this.arabicEnd == -1){