aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/latin/PrevWordsInfo.java
diff options
context:
space:
mode:
authorKeisuke Kuroyanagi <ksk@google.com>2014-06-27 17:59:21 +0900
committerKeisuke Kuroyanagi <ksk@google.com>2014-06-27 17:59:21 +0900
commit1c2f1ada8305e36defa8572da687a4596bf083ea (patch)
tree2a37c03d73a123c8a1e4ee2d66b49a6f7178a8a4 /java/src/com/android/inputmethod/latin/PrevWordsInfo.java
parent05b1e0d42f9f103516103d4d33e61862c0851e9d (diff)
downloadlatinime-1c2f1ada8305e36defa8572da687a4596bf083ea.tar.gz
latinime-1c2f1ada8305e36defa8572da687a4596bf083ea.tar.xz
latinime-1c2f1ada8305e36defa8572da687a4596bf083ea.zip
Find multiple previous word information to support n-gram.
Bug: 14425059 Change-Id: Ieace636334a9b2a094527341d4fcfc05958296c5
Diffstat (limited to 'java/src/com/android/inputmethod/latin/PrevWordsInfo.java')
-rw-r--r--java/src/com/android/inputmethod/latin/PrevWordsInfo.java43
1 files changed, 34 insertions, 9 deletions
diff --git a/java/src/com/android/inputmethod/latin/PrevWordsInfo.java b/java/src/com/android/inputmethod/latin/PrevWordsInfo.java
index 5dda44445..f45c73f53 100644
--- a/java/src/com/android/inputmethod/latin/PrevWordsInfo.java
+++ b/java/src/com/android/inputmethod/latin/PrevWordsInfo.java
@@ -27,7 +27,8 @@ import com.android.inputmethod.latin.utils.StringUtils;
public class PrevWordsInfo {
public static final PrevWordsInfo EMPTY_PREV_WORDS_INFO =
new PrevWordsInfo(WordInfo.EMPTY_WORD_INFO);
- public static final PrevWordsInfo BEGINNING_OF_SENTENCE = new PrevWordsInfo();
+ public static final PrevWordsInfo BEGINNING_OF_SENTENCE =
+ new PrevWordsInfo(WordInfo.BEGINNING_OF_SENTENCE);
/**
* Word information used to represent previous words information.
@@ -57,6 +58,24 @@ public class PrevWordsInfo {
public boolean isValid() {
return mWord != null;
}
+
+ @Override
+ public int hashCode() {
+ return Arrays.hashCode(new Object[] { mWord, mIsBeginningOfSentence } );
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (!(o instanceof WordInfo)) return false;
+ final WordInfo wordInfo = (WordInfo)o;
+ if (mWord == null || wordInfo.mWord == null) {
+ return mWord == wordInfo.mWord
+ && mIsBeginningOfSentence == wordInfo.mIsBeginningOfSentence;
+ }
+ return mWord.equals(wordInfo.mWord)
+ && mIsBeginningOfSentence == wordInfo.mIsBeginningOfSentence;
+ }
}
// The words immediately before the considered word. EMPTY_WORD_INFO element means we don't
@@ -67,16 +86,9 @@ public class PrevWordsInfo {
// calling getSuggetions* in this situation.
public WordInfo[] mPrevWordsInfo = new WordInfo[Constants.MAX_PREV_WORD_COUNT_FOR_N_GRAM];
- // Beginning of sentence.
- public PrevWordsInfo() {
- mPrevWordsInfo[0] = WordInfo.BEGINNING_OF_SENTENCE;
- Arrays.fill(mPrevWordsInfo, 1 /* start */, mPrevWordsInfo.length, WordInfo.EMPTY_WORD_INFO);
- }
-
// Construct from the previous word information.
public PrevWordsInfo(final WordInfo prevWordInfo) {
mPrevWordsInfo[0] = prevWordInfo;
- Arrays.fill(mPrevWordsInfo, 1 /* start */, mPrevWordsInfo.length, WordInfo.EMPTY_WORD_INFO);
}
// Construct from WordInfo array. n-th element represents (n+1)-th previous word's information.
@@ -116,6 +128,19 @@ public class PrevWordsInfo {
}
@Override
+ public int hashCode() {
+ return Arrays.hashCode(mPrevWordsInfo);
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (!(o instanceof PrevWordsInfo)) return false;
+ final PrevWordsInfo prevWordsInfo = (PrevWordsInfo)o;
+ return Arrays.equals(mPrevWordsInfo, prevWordsInfo.mPrevWordsInfo);
+ }
+
+ @Override
public String toString() {
final StringBuffer builder = new StringBuffer();
for (int i = 0; i < mPrevWordsInfo.length; i++) {
@@ -123,7 +148,7 @@ public class PrevWordsInfo {
builder.append("PrevWord[");
builder.append(i);
builder.append("]: ");
- if (!wordInfo.isValid()) {
+ if (wordInfo == null || !wordInfo.isValid()) {
builder.append("Empty. ");
continue;
}