@Override public String filter(CharSequence text) { StringBuilder ret = new StringBuilder(); char pre = 0; for (int i=0; i<text.length(); i++) { char c = CharNormalizer.normalize(text.charAt(i)); if (c != ' ' || pre != ' ') { ret.append(c); } pre = c; } return ret.toString(); }
@Override public String filter(CharSequence text) { StringBuilder ret = new StringBuilder(); char pre = 0; for (int i=0; i<text.length(); i++) { char c = CharNormalizer.normalize(text.charAt(i)); if (c != ' ' || pre != ' ') { ret.append(c); } pre = c; } return ret.toString(); }
public void addChar(char ch) { ch = CharNormalizer.normalize(ch); char lastChar = grams_.charAt(grams_.length() - 1); if (lastChar == ' ') { grams_ = new StringBuilder(" "); capitalword_ = false; if (ch==' ') return; } else if (grams_.length() >= N_GRAM) { grams_.deleteCharAt(0); } grams_.append(ch); if (Character.isUpperCase(ch)){ if (Character.isUpperCase(lastChar)) capitalword_ = true; } else { capitalword_ = false; } }
public void addChar(char ch) { ch = CharNormalizer.normalize(ch); char lastChar = grams_.charAt(grams_.length() - 1); if (lastChar == ' ') { grams_ = new StringBuilder(" "); capitalword_ = false; if (ch==' ') return; } else if (grams_.length() >= N_GRAM) { grams_.deleteCharAt(0); } grams_.append(ch); if (Character.isUpperCase(ch)){ if (Character.isUpperCase(lastChar)) capitalword_ = true; } else { capitalword_ = false; } }
/** * Append the target text for language detection. * If the total size of target text exceeds the limit size , * the rest is cut down. * * @param text the target text to append */ @Override public TextObject append(CharSequence text) { if (maxTextLength>0 && stringBuilder.length()>=maxTextLength) return this; text = textFilter.filter(text); //unfortunately this code can't be put into a TextFilter because: //1) the limit could not be detected early, a lot of work would be done to waste time and memory //2) the last character of the existing string builder could not be seen. if it is a space, we don't want // to add yet another space. char pre = stringBuilder.length()==0 ? 0 : stringBuilder.charAt(stringBuilder.length()-1); for (int i=0; i<text.length() && (maxTextLength==0 || stringBuilder.length()<maxTextLength); i++) { char c = CharNormalizer.normalize(text.charAt(i)); if (c != ' ' || pre != ' ') { stringBuilder.append(c); } pre = c; } return this; }
/** * Append the target text for language detection. * If the total size of target text exceeds the limit size , * the rest is cut down. * * @param text the target text to append */ @Override public TextObject append(CharSequence text) { if (maxTextLength>0 && stringBuilder.length()>=maxTextLength) return this; text = textFilter.filter(text); //unfortunately this code can't be put into a TextFilter because: //1) the limit could not be detected early, a lot of work would be done to waste time and memory //2) the last character of the existing string builder could not be seen. if it is a space, we don't want // to add yet another space. char pre = stringBuilder.length()==0 ? 0 : stringBuilder.charAt(stringBuilder.length()-1); for (int i=0; i<text.length() && (maxTextLength==0 || stringBuilder.length()<maxTextLength); i++) { char c = CharNormalizer.normalize(text.charAt(i)); if (c != ' ' || pre != ' ') { stringBuilder.append(c); } pre = c; } return this; }