Consolidate WordProperty and Word.

Bug: 11281877
Bug: 12810574
Change-Id: I9dc99188f80f25a8780c1860dab46e4aa80a23e5
diff --git a/tools/dicttool/Android.mk b/tools/dicttool/Android.mk
index adfb920..5d1a30e 100644
--- a/tools/dicttool/Android.mk
+++ b/tools/dicttool/Android.mk
@@ -48,8 +48,7 @@
         $(LATINIME_CORE_SOURCE_DIRECTORY)/utils/JniUtils.java \
         $(LATINIME_CORE_SOURCE_DIRECTORY)/utils/LocaleUtils.java \
         $(LATINIME_CORE_SOURCE_DIRECTORY)/utils/ResizableIntArray.java \
-        $(LATINIME_CORE_SOURCE_DIRECTORY)/utils/StringUtils.java \
-        $(LATINIME_CORE_SOURCE_DIRECTORY)/utils/WordProperty.java
+        $(LATINIME_CORE_SOURCE_DIRECTORY)/utils/StringUtils.java
 
 DICTTOOL_ONDEVICE_TESTS_DIRECTORY := \
         $(LATINIME_LOCAL_DIR)/tests/src/com/android/inputmethod/latin/makedict/
diff --git a/tools/dicttool/src/com/android/inputmethod/latin/dicttool/CombinedInputOutput.java b/tools/dicttool/src/com/android/inputmethod/latin/dicttool/CombinedInputOutput.java
index b984060..eae9d9f 100644
--- a/tools/dicttool/src/com/android/inputmethod/latin/dicttool/CombinedInputOutput.java
+++ b/tools/dicttool/src/com/android/inputmethod/latin/dicttool/CombinedInputOutput.java
@@ -21,7 +21,7 @@
 import com.android.inputmethod.latin.makedict.FusionDictionary.DictionaryOptions;
 import com.android.inputmethod.latin.makedict.FusionDictionary.PtNodeArray;
 import com.android.inputmethod.latin.makedict.FusionDictionary.WeightedString;
-import com.android.inputmethod.latin.makedict.Word;
+import com.android.inputmethod.latin.makedict.WordProperty;
 
 import java.io.BufferedReader;
 import java.io.File;
@@ -45,7 +45,7 @@
     private static final String DICTIONARY_TAG = "dictionary";
     private static final String BIGRAM_TAG = "bigram";
     private static final String SHORTCUT_TAG = "shortcut";
-    private static final String FREQUENCY_TAG = "f";
+    private static final String PROBABILITY_TAG = "f";
     private static final String WORD_TAG = "word";
     private static final String NOT_A_WORD_TAG = "not_a_word";
     private static final String WHITELIST_TAG = "whitelist";
@@ -138,7 +138,7 @@
                     if (2 != params.length) throw new RuntimeException("Wrong format : " + line);
                     if (WORD_TAG.equals(params[0])) {
                         word = params[1];
-                    } else if (FREQUENCY_TAG.equals(params[0])) {
+                    } else if (PROBABILITY_TAG.equals(params[0])) {
                         freq = Integer.parseInt(params[1]);
                     } else if (NOT_A_WORD_TAG.equals(params[0])) {
                         isNotAWord = "true".equals(params[1]);
@@ -152,7 +152,7 @@
                     if (2 != params.length) throw new RuntimeException("Wrong format : " + line);
                     if (SHORTCUT_TAG.equals(params[0])) {
                         shortcut = params[1];
-                    } else if (FREQUENCY_TAG.equals(params[0])) {
+                    } else if (PROBABILITY_TAG.equals(params[0])) {
                         shortcutFreq = WHITELIST_TAG.equals(params[1])
                                 ? FormatSpec.SHORTCUT_WHITELIST_FREQUENCY
                                 : Integer.parseInt(params[1]);
@@ -171,7 +171,7 @@
                     if (2 != params.length) throw new RuntimeException("Wrong format : " + line);
                     if (BIGRAM_TAG.equals(params[0])) {
                         secondWordOfBigram = params[1];
-                    } else if (FREQUENCY_TAG.equals(params[0])) {
+                    } else if (PROBABILITY_TAG.equals(params[0])) {
                         bigramFreq = Integer.parseInt(params[1]);
                     }
                 }
@@ -200,9 +200,10 @@
      */
     public static void writeDictionaryCombined(Writer destination, FusionDictionary dict)
             throws IOException {
-        final TreeSet<Word> set = new TreeSet<Word>();
-        for (Word word : dict) {
-            set.add(word); // This for ordering by frequency, then by asciibetic order
+        final TreeSet<WordProperty> wordPropertiesInDict = new TreeSet<WordProperty>();
+        for (WordProperty wordProperty: dict) {
+            // This for ordering by frequency, then by asciibetic order
+            wordPropertiesInDict.add(wordProperty);
         }
         final HashMap<String, String> options = dict.mOptions.mAttributes;
         destination.write(DICTIONARY_TAG + "=");
@@ -215,20 +216,20 @@
             destination.write("," + key + "=" + value);
         }
         destination.write("\n");
-        for (Word word : set) {
-            destination.write(" " + WORD_TAG + "=" + word.mWord + ","
-                    + FREQUENCY_TAG + "=" + word.mFrequency
-                    + (word.mIsNotAWord ? "," + NOT_A_WORD_TAG + "=true\n" : "\n"));
-            if (null != word.mShortcutTargets) {
-                for (WeightedString target : word.mShortcutTargets) {
+        for (WordProperty wordProperty : wordPropertiesInDict) {
+            destination.write(" " + WORD_TAG + "=" + wordProperty.mWord + ","
+                    + PROBABILITY_TAG + "=" + wordProperty.getProbability()
+                    + (wordProperty.mIsNotAWord ? "," + NOT_A_WORD_TAG + "=true\n" : "\n"));
+            if (null != wordProperty.mShortcutTargets) {
+                for (WeightedString target : wordProperty.mShortcutTargets) {
                     destination.write("  " + SHORTCUT_TAG + "=" + target.mWord + ","
-                            + FREQUENCY_TAG + "=" + target.getProbability() + "\n");
+                            + PROBABILITY_TAG + "=" + target.getProbability() + "\n");
                 }
             }
-            if (null != word.mBigrams) {
-                for (WeightedString bigram : word.mBigrams) {
+            if (null != wordProperty.mBigrams) {
+                for (WeightedString bigram : wordProperty.mBigrams) {
                     destination.write("  " + BIGRAM_TAG + "=" + bigram.mWord + ","
-                            + FREQUENCY_TAG + "=" + bigram.getProbability() + "\n");
+                            + PROBABILITY_TAG + "=" + bigram.getProbability() + "\n");
                 }
             }
         }
diff --git a/tools/dicttool/src/com/android/inputmethod/latin/dicttool/Diff.java b/tools/dicttool/src/com/android/inputmethod/latin/dicttool/Diff.java
index c9f6bd5..9947608 100644
--- a/tools/dicttool/src/com/android/inputmethod/latin/dicttool/Diff.java
+++ b/tools/dicttool/src/com/android/inputmethod/latin/dicttool/Diff.java
@@ -19,7 +19,7 @@
 import com.android.inputmethod.latin.makedict.FusionDictionary;
 import com.android.inputmethod.latin.makedict.FusionDictionary.PtNode;
 import com.android.inputmethod.latin.makedict.FusionDictionary.WeightedString;
-import com.android.inputmethod.latin.makedict.Word;
+import com.android.inputmethod.latin.makedict.WordProperty;
 
 import java.util.Arrays;
 import java.util.ArrayList;
@@ -108,42 +108,46 @@
 
     private static void diffWords(final FusionDictionary dict0, final FusionDictionary dict1) {
         boolean hasDifferences = false;
-        for (final Word word0 : dict0) {
-            final PtNode word1 = FusionDictionary.findWordInTree(dict1.mRootNodeArray,
-                    word0.mWord);
-            if (null == word1) {
+        for (final WordProperty word0Property : dict0) {
+            final PtNode word1PtNode = FusionDictionary.findWordInTree(dict1.mRootNodeArray,
+                    word0Property.mWord);
+            if (null == word1PtNode) {
                 // This word is not in dict1
-                System.out.println("Deleted: " + word0.mWord + " " + word0.mFrequency);
+                System.out.println("Deleted: " + word0Property.mWord + " "
+                        + word0Property.getProbability());
                 hasDifferences = true;
             } else {
                 // We found the word. Compare frequencies, shortcuts, bigrams
-                if (word0.mFrequency != word1.getFrequency()) {
-                    System.out.println("Freq changed: " + word0.mWord + " " + word0.mFrequency
-                            + " -> " + word1.getFrequency());
+                if (word0Property.getProbability() != word1PtNode.getFrequency()) {
+                    System.out.println("Probability changed: " + word0Property.mWord + " "
+                            + word0Property.getProbability() + " -> " + word1PtNode.getFrequency());
                     hasDifferences = true;
                 }
-                if (word0.mIsNotAWord != word1.getIsNotAWord()) {
-                    System.out.println("Not a word: " + word0.mWord + " " + word0.mIsNotAWord
-                            + " -> " + word1.getIsNotAWord());
+                if (word0Property.mIsNotAWord != word1PtNode.getIsNotAWord()) {
+                    System.out.println("Not a word: " + word0Property.mWord + " "
+                            + word0Property.mIsNotAWord + " -> " + word1PtNode.getIsNotAWord());
                     hasDifferences = true;
                 }
-                if (word0.mIsBlacklistEntry != word1.getIsBlacklistEntry()) {
-                    System.out.println("Blacklist: " + word0.mWord + " " + word0.mIsBlacklistEntry
-                            + " -> " + word1.getIsBlacklistEntry());
+                if (word0Property.mIsBlacklistEntry != word1PtNode.getIsBlacklistEntry()) {
+                    System.out.println("Blacklist: " + word0Property.mWord + " "
+                            + word0Property.mIsBlacklistEntry + " -> "
+                            + word1PtNode.getIsBlacklistEntry());
                     hasDifferences = true;
                 }
-                hasDifferences |= hasAttributesDifferencesAndPrintThemIfAny(word0.mWord,
-                        "Bigram", word0.mBigrams, word1.getBigrams());
-                hasDifferences |= hasAttributesDifferencesAndPrintThemIfAny(word0.mWord,
-                        "Shortcut", word0.mShortcutTargets, word1.getShortcutTargets());
+                hasDifferences |= hasAttributesDifferencesAndPrintThemIfAny(word0Property.mWord,
+                        "Bigram", word0Property.mBigrams, word1PtNode.getBigrams());
+                hasDifferences |= hasAttributesDifferencesAndPrintThemIfAny(word0Property.mWord,
+                        "Shortcut", word0Property.mShortcutTargets,
+                        word1PtNode.getShortcutTargets());
             }
         }
-        for (final Word word1 : dict1) {
-            final PtNode word0 = FusionDictionary.findWordInTree(dict0.mRootNodeArray,
-                    word1.mWord);
-            if (null == word0) {
+        for (final WordProperty word1Property : dict1) {
+            final PtNode word0PtNode = FusionDictionary.findWordInTree(dict0.mRootNodeArray,
+                    word1Property.mWord);
+            if (null == word0PtNode) {
                 // This word is not in dict0
-                System.out.println("Added: " + word1.mWord + " " + word1.mFrequency);
+                System.out.println("Added: " + word1Property.mWord + " "
+                        + word1Property.getProbability());
                 hasDifferences = true;
             }
         }
diff --git a/tools/dicttool/src/com/android/inputmethod/latin/dicttool/Info.java b/tools/dicttool/src/com/android/inputmethod/latin/dicttool/Info.java
index 8f17fcd..c1eb0f8 100644
--- a/tools/dicttool/src/com/android/inputmethod/latin/dicttool/Info.java
+++ b/tools/dicttool/src/com/android/inputmethod/latin/dicttool/Info.java
@@ -20,7 +20,7 @@
 import com.android.inputmethod.latin.makedict.FusionDictionary;
 import com.android.inputmethod.latin.makedict.FusionDictionary.PtNode;
 import com.android.inputmethod.latin.makedict.FusionDictionary.WeightedString;
-import com.android.inputmethod.latin.makedict.Word;
+import com.android.inputmethod.latin.makedict.WordProperty;
 
 import java.util.Arrays;
 import java.util.ArrayList;
@@ -43,14 +43,14 @@
         int bigramCount = 0;
         int shortcutCount = 0;
         int whitelistCount = 0;
-        for (final Word w : dict) {
+        for (final WordProperty wordProperty : dict) {
             ++wordCount;
-            if (null != w.mBigrams) {
-                bigramCount += w.mBigrams.size();
+            if (null != wordProperty.mBigrams) {
+                bigramCount += wordProperty.mBigrams.size();
             }
-            if (null != w.mShortcutTargets) {
-                shortcutCount += w.mShortcutTargets.size();
-                for (WeightedString shortcutTarget : w.mShortcutTargets) {
+            if (null != wordProperty.mShortcutTargets) {
+                shortcutCount += wordProperty.mShortcutTargets.size();
+                for (WeightedString shortcutTarget : wordProperty.mShortcutTargets) {
                     if (FormatSpec.SHORTCUT_WHITELIST_FREQUENCY
                             == shortcutTarget.getProbability()) {
                         ++whitelistCount;
diff --git a/tools/dicttool/src/com/android/inputmethod/latin/dicttool/XmlDictInputOutput.java b/tools/dicttool/src/com/android/inputmethod/latin/dicttool/XmlDictInputOutput.java
index cdc487b..c6c60b8 100644
--- a/tools/dicttool/src/com/android/inputmethod/latin/dicttool/XmlDictInputOutput.java
+++ b/tools/dicttool/src/com/android/inputmethod/latin/dicttool/XmlDictInputOutput.java
@@ -20,7 +20,7 @@
 import com.android.inputmethod.latin.makedict.FusionDictionary.DictionaryOptions;
 import com.android.inputmethod.latin.makedict.FusionDictionary.PtNodeArray;
 import com.android.inputmethod.latin.makedict.FusionDictionary.WeightedString;
-import com.android.inputmethod.latin.makedict.Word;
+import com.android.inputmethod.latin.makedict.WordProperty;
 
 import java.io.BufferedReader;
 import java.io.File;
@@ -52,7 +52,7 @@
     private static final String WORD_TAG = "w";
     private static final String BIGRAM_TAG = "bigram";
     private static final String SHORTCUT_TAG = "shortcut";
-    private static final String FREQUENCY_ATTR = "f";
+    private static final String PROBABILITY_ATTR = "f";
     private static final String WORD_ATTR = "word";
     private static final String NOT_A_WORD_ATTR = "not_a_word";
 
@@ -107,7 +107,7 @@
                 mWord = "";
                 for (int attrIndex = 0; attrIndex < attrs.getLength(); ++attrIndex) {
                     final String attrName = attrs.getLocalName(attrIndex);
-                    if (FREQUENCY_ATTR.equals(attrName)) {
+                    if (PROBABILITY_ATTR.equals(attrName)) {
                         mFreq = Integer.parseInt(attrs.getValue(attrIndex));
                     }
                 }
@@ -348,9 +348,9 @@
      */
     public static void writeDictionaryXml(Writer destination, FusionDictionary dict)
             throws IOException {
-        final TreeSet<Word> set = new TreeSet<Word>();
-        for (Word word : dict) {
-            set.add(word);
+        final TreeSet<WordProperty> wordPropertiesInDict = new TreeSet<WordProperty>();
+        for (WordProperty wordProperty : dict) {
+            wordPropertiesInDict.add(wordProperty);
         }
         // TODO: use an XMLSerializer if this gets big
         destination.write("<wordlist format=\"2\"");
@@ -361,23 +361,24 @@
         }
         destination.write(">\n");
         destination.write("<!-- Warning: there is no code to read this format yet. -->\n");
-        for (Word word : set) {
-            destination.write("  <" + WORD_TAG + " " + WORD_ATTR + "=\"" + word.mWord + "\" "
-                    + FREQUENCY_ATTR + "=\"" + word.mFrequency
-                    + (word.mIsNotAWord ? "\" " + NOT_A_WORD_ATTR + "=\"true" : "") + "\">");
-            if (null != word.mShortcutTargets) {
+        for (WordProperty wordProperty : wordPropertiesInDict) {
+            destination.write("  <" + WORD_TAG + " " + WORD_ATTR + "=\"" + wordProperty.mWord
+                    + "\" " + PROBABILITY_ATTR + "=\"" + wordProperty.getProbability()
+                    + (wordProperty.mIsNotAWord ? "\" " + NOT_A_WORD_ATTR + "=\"true" : "")
+                    + "\">");
+            if (null != wordProperty.mShortcutTargets) {
                 destination.write("\n");
-                for (WeightedString target : word.mShortcutTargets) {
-                    destination.write("    <" + SHORTCUT_TAG + " " + FREQUENCY_ATTR + "=\""
+                for (WeightedString target : wordProperty.mShortcutTargets) {
+                    destination.write("    <" + SHORTCUT_TAG + " " + PROBABILITY_ATTR + "=\""
                             + target.getProbability() + "\">" + target.mWord + "</" + SHORTCUT_TAG
                             + ">\n");
                 }
                 destination.write("  ");
             }
-            if (null != word.mBigrams) {
+            if (null != wordProperty.mBigrams) {
                 destination.write("\n");
-                for (WeightedString bigram : word.mBigrams) {
-                    destination.write("    <" + BIGRAM_TAG + " " + FREQUENCY_ATTR + "=\""
+                for (WeightedString bigram : wordProperty.mBigrams) {
+                    destination.write("    <" + BIGRAM_TAG + " " + PROBABILITY_ATTR + "=\""
                             + bigram.getProbability() + "\">" + bigram.mWord
                             + "</" + BIGRAM_TAG + ">\n");
                 }
diff --git a/tools/dicttool/tests/com/android/inputmethod/latin/makedict/FusionDictionaryTest.java b/tools/dicttool/tests/com/android/inputmethod/latin/makedict/FusionDictionaryTest.java
index 76dadc2..1915464 100644
--- a/tools/dicttool/tests/com/android/inputmethod/latin/makedict/FusionDictionaryTest.java
+++ b/tools/dicttool/tests/com/android/inputmethod/latin/makedict/FusionDictionaryTest.java
@@ -20,7 +20,7 @@
 import com.android.inputmethod.latin.makedict.FusionDictionary.PtNode;
 import com.android.inputmethod.latin.makedict.FusionDictionary.DictionaryOptions;
 import com.android.inputmethod.latin.makedict.FusionDictionary.PtNodeArray;
-import com.android.inputmethod.latin.makedict.Word;
+import com.android.inputmethod.latin.makedict.WordProperty;
 
 import junit.framework.TestCase;
 
@@ -87,8 +87,8 @@
     }
 
     private void dumpDict(final FusionDictionary dict) {
-        for (Word w : dict) {
-            System.out.println("Word " + dumpWord(w.mWord));
+        for (WordProperty wordProperty : dict) {
+            System.out.println("Word " + dumpWord(wordProperty.mWord));
         }
     }