aboutsummaryrefslogtreecommitdiffstats
path: root/java
diff options
context:
space:
mode:
authorJean Chalard <jchalard@google.com>2014-10-03 09:33:28 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2014-10-03 09:33:28 +0000
commit332f43275ddbefa5f2376381f6f8d6115d69b3b4 (patch)
treec3d012f915587f7bc3fee31d722d658eeac81992 /java
parentd415747a27514281e9040bcd9c8cb135a0ca2f48 (diff)
parentb28d1cc48794019e63b95b197a6b9cd3fe64275c (diff)
downloadlatinime-332f43275ddbefa5f2376381f6f8d6115d69b3b4.tar.gz
latinime-332f43275ddbefa5f2376381f6f8d6115d69b3b4.tar.xz
latinime-332f43275ddbefa5f2376381f6f8d6115d69b3b4.zip
Merge "Fix a behavior change in dicttool"
Diffstat (limited to 'java')
-rw-r--r--java/src/com/android/inputmethod/latin/makedict/WordProperty.java31
1 files changed, 23 insertions, 8 deletions
diff --git a/java/src/com/android/inputmethod/latin/makedict/WordProperty.java b/java/src/com/android/inputmethod/latin/makedict/WordProperty.java
index 46705f9db..a180d060e 100644
--- a/java/src/com/android/inputmethod/latin/makedict/WordProperty.java
+++ b/java/src/com/android/inputmethod/latin/makedict/WordProperty.java
@@ -54,11 +54,15 @@ public final class WordProperty implements Comparable<WordProperty> {
mWord = word;
mProbabilityInfo = probabilityInfo;
mShortcutTargets = shortcutTargets;
- mNgrams = new ArrayList<>();
- final NgramContext ngramContext = new NgramContext(new WordInfo(mWord));
- if (bigrams != null) {
- for (final WeightedString bigramTarget : bigrams) {
- mNgrams.add(new NgramProperty(bigramTarget, ngramContext));
+ if (null == bigrams) {
+ mNgrams = null;
+ } else {
+ mNgrams = new ArrayList<>();
+ final NgramContext ngramContext = new NgramContext(new WordInfo(mWord));
+ if (bigrams != null) {
+ for (final WeightedString bigramTarget : bigrams) {
+ mNgrams.add(new NgramProperty(bigramTarget, ngramContext));
+ }
}
}
mIsBeginningOfSentence = false;
@@ -87,7 +91,7 @@ public final class WordProperty implements Comparable<WordProperty> {
mWord = StringUtils.getStringFromNullTerminatedCodePointArray(codePoints);
mProbabilityInfo = createProbabilityInfoFromArray(probabilityInfo);
mShortcutTargets = new ArrayList<>();
- mNgrams = new ArrayList<>();
+ final ArrayList<NgramProperty> ngrams = new ArrayList<>();
mIsBeginningOfSentence = isBeginningOfSentence;
mIsNotAWord = isNotAWord;
mIsBlacklistEntry = isBlacklisted;
@@ -104,8 +108,9 @@ public final class WordProperty implements Comparable<WordProperty> {
final WeightedString ngramTarget = new WeightedString(ngramTargetString,
createProbabilityInfoFromArray(bigramProbabilityInfo.get(i)));
// TODO: Support n-gram.
- mNgrams.add(new NgramProperty(ngramTarget, ngramContext));
+ ngrams.add(new NgramProperty(ngramTarget, ngramContext));
}
+ mNgrams = ngrams.isEmpty() ? null : ngrams;
final int shortcutTargetCount = shortcutTargets.size();
for (int i = 0; i < shortcutTargetCount; i++) {
@@ -118,6 +123,9 @@ public final class WordProperty implements Comparable<WordProperty> {
// TODO: Remove
public ArrayList<WeightedString> getBigrams() {
+ if (null == mNgrams) {
+ return null;
+ }
final ArrayList<WeightedString> bigrams = new ArrayList<>();
for (final NgramProperty ngram : mNgrams) {
if (ngram.mNgramContext.getPrevWordCount() == 1) {
@@ -167,11 +175,18 @@ public final class WordProperty implements Comparable<WordProperty> {
if (!(o instanceof WordProperty)) return false;
WordProperty w = (WordProperty)o;
return mProbabilityInfo.equals(w.mProbabilityInfo) && mWord.equals(w.mWord)
- && mShortcutTargets.equals(w.mShortcutTargets) && mNgrams.equals(w.mNgrams)
+ && mShortcutTargets.equals(w.mShortcutTargets) && equals(mNgrams, w.mNgrams)
&& mIsNotAWord == w.mIsNotAWord && mIsBlacklistEntry == w.mIsBlacklistEntry
&& mHasNgrams == w.mHasNgrams && mHasShortcuts && w.mHasNgrams;
}
+ private <T> boolean equals(final ArrayList<T> a, final ArrayList<T> b) {
+ if (null == a) {
+ return null == b;
+ }
+ return a.equals(b);
+ }
+
@Override
public int hashCode() {
if (mHashCode == 0) {