parent
261622aa1e
commit
845c061970
|
@ -132,7 +132,8 @@ public class PrevWordsInfo {
|
|||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Arrays.hashCode(mPrevWordsInfo);
|
||||
// Just for having equals().
|
||||
return mPrevWordsInfo[0].hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -140,7 +141,23 @@ public class PrevWordsInfo {
|
|||
if (this == o) return true;
|
||||
if (!(o instanceof PrevWordsInfo)) return false;
|
||||
final PrevWordsInfo prevWordsInfo = (PrevWordsInfo)o;
|
||||
return Arrays.equals(mPrevWordsInfo, prevWordsInfo.mPrevWordsInfo);
|
||||
|
||||
final int minLength = Math.min(mPrevWordsInfo.length, prevWordsInfo.mPrevWordsInfo.length);
|
||||
for (int i = 0; i < minLength; i++) {
|
||||
if (!mPrevWordsInfo[i].equals(prevWordsInfo.mPrevWordsInfo[i])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
final WordInfo[] longerWordsInfo =
|
||||
(mPrevWordsInfo.length > prevWordsInfo.mPrevWordsInfo.length) ?
|
||||
mPrevWordsInfo : prevWordsInfo.mPrevWordsInfo;
|
||||
for (int i = minLength; i < longerWordsInfo.length; i++) {
|
||||
if (longerWordsInfo[i] != null
|
||||
&& !WordInfo.EMPTY_WORD_INFO.equals(longerWordsInfo[i])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -151,7 +168,11 @@ public class PrevWordsInfo {
|
|||
builder.append("PrevWord[");
|
||||
builder.append(i);
|
||||
builder.append("]: ");
|
||||
if (wordInfo == null || !wordInfo.isValid()) {
|
||||
if (wordInfo == null) {
|
||||
builder.append("null. ");
|
||||
continue;
|
||||
}
|
||||
if (!wordInfo.isValid()) {
|
||||
builder.append("Empty. ");
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
package com.android.inputmethod.latin.utils;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import com.android.inputmethod.latin.Constants;
|
||||
|
@ -56,6 +57,7 @@ public final class PrevWordsInfoUtils {
|
|||
if (prev == null) return PrevWordsInfo.EMPTY_PREV_WORDS_INFO;
|
||||
final String[] w = SPACE_REGEX.split(prev);
|
||||
final WordInfo[] prevWordsInfo = new WordInfo[Constants.MAX_PREV_WORD_COUNT_FOR_N_GRAM];
|
||||
Arrays.fill(prevWordsInfo, WordInfo.EMPTY_WORD_INFO);
|
||||
for (int i = 0; i < prevWordsInfo.length; i++) {
|
||||
final int focusedWordIndex = w.length - n - i;
|
||||
// Referring to the word after the focused word.
|
||||
|
@ -66,7 +68,6 @@ public final class PrevWordsInfoUtils {
|
|||
if (spacingAndPunctuations.isWordConnector(firstChar)) {
|
||||
// The word following the focused word is starting with a word connector.
|
||||
// TODO: Return meaningful context for this case.
|
||||
prevWordsInfo[i] = WordInfo.EMPTY_WORD_INFO;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -93,7 +94,6 @@ public final class PrevWordsInfoUtils {
|
|||
// TODO: Return meaningful context for this case.
|
||||
if (spacingAndPunctuations.isWordSeparator(lastChar)
|
||||
|| spacingAndPunctuations.isWordConnector(lastChar)) {
|
||||
prevWordsInfo[i] = WordInfo.EMPTY_WORD_INFO;
|
||||
break;
|
||||
}
|
||||
prevWordsInfo[i] = new WordInfo(focusedWord);
|
||||
|
|
Loading…
Reference in New Issue