diff --git a/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java b/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java index 8e1675b2a4dd794d47121935f30c27d4659abfa4..4dee84a7b35f3419ede8d82111c20c7b1f4b6f24 100644 --- a/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java +++ b/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java @@ -267,9 +267,9 @@ abstract public class ExpandableBinaryDictionary extends Dictionary { protected Map<String, String> getHeaderAttributeMap() { HashMap<String, String> attributeMap = new HashMap<String, String>(); - attributeMap.put(FormatSpec.FileHeader.DICTIONARY_ID_ATTRIBUTE, mDictName); - attributeMap.put(FormatSpec.FileHeader.DICTIONARY_LOCALE_ATTRIBUTE, mLocale.toString()); - attributeMap.put(FormatSpec.FileHeader.DICTIONARY_VERSION_ATTRIBUTE, + attributeMap.put(FormatSpec.FileHeader.DICTIONARY_ID_KEY, mDictName); + attributeMap.put(FormatSpec.FileHeader.DICTIONARY_LOCALE_KEY, mLocale.toString()); + attributeMap.put(FormatSpec.FileHeader.DICTIONARY_VERSION_KEY, String.valueOf(TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis()))); return attributeMap; } diff --git a/java/src/com/android/inputmethod/latin/makedict/AbstractDictDecoder.java b/java/src/com/android/inputmethod/latin/makedict/AbstractDictDecoder.java index 370782b332b41ee2b19df4ca6a70944b293a43a6..1a9118147cb06d31020b7c7111fff479d373e79c 100644 --- a/java/src/com/android/inputmethod/latin/makedict/AbstractDictDecoder.java +++ b/java/src/com/android/inputmethod/latin/makedict/AbstractDictDecoder.java @@ -60,7 +60,7 @@ public abstract class AbstractDictDecoder implements DictDecoder { final FileHeader header = new FileHeader(headerSize, new FusionDictionary.DictionaryOptions(attributes), new FormatOptions(version, FileHeader.ATTRIBUTE_VALUE_TRUE.equals( - attributes.get(FileHeader.HAS_HISTORICAL_INFO_ATTRIBUTE)))); + attributes.get(FileHeader.HAS_HISTORICAL_INFO_KEY)))); return header; } diff --git a/java/src/com/android/inputmethod/latin/makedict/FormatSpec.java b/java/src/com/android/inputmethod/latin/makedict/FormatSpec.java index 61c17fc4630fcb8a4416e9c5d804c57c0d881938..74e305976356ec725c67f6c20739f6dd2e3865b9 100644 --- a/java/src/com/android/inputmethod/latin/makedict/FormatSpec.java +++ b/java/src/com/android/inputmethod/latin/makedict/FormatSpec.java @@ -336,16 +336,19 @@ public final class FormatSpec { public final int mBodyOffset; public final DictionaryOptions mDictionaryOptions; public final FormatOptions mFormatOptions; + // Note that these are corresponding definitions in native code in latinime::HeaderPolicy // and latinime::HeaderReadWriteUtils. - public static final String USES_FORGETTING_CURVE_ATTRIBUTE = "USES_FORGETTING_CURVE"; - public static final String HAS_HISTORICAL_INFO_ATTRIBUTE = "HAS_HISTORICAL_INFO"; + // TODO: Standardize the key names and bump up the format version, taking care not to + // break format version 2 dictionaries. + public static final String DICTIONARY_VERSION_KEY = "version"; + public static final String DICTIONARY_LOCALE_KEY = "locale"; + public static final String DICTIONARY_ID_KEY = "dictionary"; + public static final String DICTIONARY_DESCRIPTION_KEY = "description"; + public static final String DICTIONARY_DATE_KEY = "date"; + public static final String HAS_HISTORICAL_INFO_KEY = "HAS_HISTORICAL_INFO"; + public static final String USES_FORGETTING_CURVE_KEY = "USES_FORGETTING_CURVE"; public static final String ATTRIBUTE_VALUE_TRUE = "1"; - - public static final String DICTIONARY_VERSION_ATTRIBUTE = "version"; - public static final String DICTIONARY_LOCALE_ATTRIBUTE = "locale"; - public static final String DICTIONARY_ID_ATTRIBUTE = "dictionary"; - private static final String DICTIONARY_DESCRIPTION_ATTRIBUTE = "description"; public FileHeader(final int headerSize, final DictionaryOptions dictionaryOptions, final FormatOptions formatOptions) throws UnsupportedFormatException { mDictionaryOptions = dictionaryOptions; @@ -365,24 +368,24 @@ public final class FormatSpec { // Helper method to get the locale as a String public String getLocaleString() { - return mDictionaryOptions.mAttributes.get(FileHeader.DICTIONARY_LOCALE_ATTRIBUTE); + return mDictionaryOptions.mAttributes.get(FileHeader.DICTIONARY_LOCALE_KEY); } // Helper method to get the version String public String getVersion() { - return mDictionaryOptions.mAttributes.get(FileHeader.DICTIONARY_VERSION_ATTRIBUTE); + return mDictionaryOptions.mAttributes.get(FileHeader.DICTIONARY_VERSION_KEY); } // Helper method to get the dictionary ID as a String public String getId() { - return mDictionaryOptions.mAttributes.get(FileHeader.DICTIONARY_ID_ATTRIBUTE); + return mDictionaryOptions.mAttributes.get(FileHeader.DICTIONARY_ID_KEY); } // Helper method to get the description public String getDescription() { // TODO: Right now each dictionary file comes with a description in its own language. // It will display as is no matter the device's locale. It should be internationalized. - return mDictionaryOptions.mAttributes.get(FileHeader.DICTIONARY_DESCRIPTION_ATTRIBUTE); + return mDictionaryOptions.mAttributes.get(FileHeader.DICTIONARY_DESCRIPTION_KEY); } } diff --git a/java/src/com/android/inputmethod/latin/makedict/Ver4DictEncoder.java b/java/src/com/android/inputmethod/latin/makedict/Ver4DictEncoder.java index d34aa171ee9ff3684d5574d5d009258606697c92..b12f79b0782f7bf34c3c56e986874bfbda9d7535 100644 --- a/java/src/com/android/inputmethod/latin/makedict/Ver4DictEncoder.java +++ b/java/src/com/android/inputmethod/latin/makedict/Ver4DictEncoder.java @@ -62,7 +62,7 @@ public class Ver4DictEncoder implements DictEncoder { final BinaryDictionary binaryDict = new BinaryDictionary(mDictPlacedDir.getAbsolutePath(), 0l, mDictPlacedDir.length(), true /* useFullEditDistance */, LocaleUtils.constructLocaleFromString(dict.mOptions.mAttributes.get( - FormatSpec.FileHeader.DICTIONARY_LOCALE_ATTRIBUTE)), + FormatSpec.FileHeader.DICTIONARY_LOCALE_KEY)), Dictionary.TYPE_USER /* Dictionary type. Does not matter for us */, true /* isUpdatable */); if (!binaryDict.isValidDictionary()) { diff --git a/java/src/com/android/inputmethod/latin/personalization/DecayingExpandableBinaryDictionaryBase.java b/java/src/com/android/inputmethod/latin/personalization/DecayingExpandableBinaryDictionaryBase.java index 4a610e6f94e74b22787574f5499c069ad711539f..d636a253ab3c54cd5ef8ba535e95bdfc9b222bec 100644 --- a/java/src/com/android/inputmethod/latin/personalization/DecayingExpandableBinaryDictionaryBase.java +++ b/java/src/com/android/inputmethod/latin/personalization/DecayingExpandableBinaryDictionaryBase.java @@ -95,13 +95,13 @@ public abstract class DecayingExpandableBinaryDictionaryBase extends ExpandableB @Override protected Map<String, String> getHeaderAttributeMap() { HashMap<String, String> attributeMap = new HashMap<String, String>(); - attributeMap.put(FormatSpec.FileHeader.USES_FORGETTING_CURVE_ATTRIBUTE, + attributeMap.put(FormatSpec.FileHeader.USES_FORGETTING_CURVE_KEY, FormatSpec.FileHeader.ATTRIBUTE_VALUE_TRUE); - attributeMap.put(FormatSpec.FileHeader.HAS_HISTORICAL_INFO_ATTRIBUTE, + attributeMap.put(FormatSpec.FileHeader.HAS_HISTORICAL_INFO_KEY, FormatSpec.FileHeader.ATTRIBUTE_VALUE_TRUE); - attributeMap.put(FormatSpec.FileHeader.DICTIONARY_ID_ATTRIBUTE, mDictName); - attributeMap.put(FormatSpec.FileHeader.DICTIONARY_LOCALE_ATTRIBUTE, mLocale.toString()); - attributeMap.put(FormatSpec.FileHeader.DICTIONARY_VERSION_ATTRIBUTE, + attributeMap.put(FormatSpec.FileHeader.DICTIONARY_ID_KEY, mDictName); + attributeMap.put(FormatSpec.FileHeader.DICTIONARY_LOCALE_KEY, mLocale.toString()); + attributeMap.put(FormatSpec.FileHeader.DICTIONARY_VERSION_KEY, String.valueOf(TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis()))); return attributeMap; } diff --git a/java/src/com/android/inputmethod/latin/utils/UserHistoryDictIOUtils.java b/java/src/com/android/inputmethod/latin/utils/UserHistoryDictIOUtils.java index a6ae640d3bf57c46053b9cc5c7ec999d1f0ff141..7af03da599a0e5a031e3566923caad824576fe59 100644 --- a/java/src/com/android/inputmethod/latin/utils/UserHistoryDictIOUtils.java +++ b/java/src/com/android/inputmethod/latin/utils/UserHistoryDictIOUtils.java @@ -22,6 +22,7 @@ import com.android.inputmethod.annotations.UsedForTesting; import com.android.inputmethod.latin.makedict.BinaryDictIOUtils; import com.android.inputmethod.latin.makedict.DictDecoder; import com.android.inputmethod.latin.makedict.DictEncoder; +import com.android.inputmethod.latin.makedict.FormatSpec; import com.android.inputmethod.latin.makedict.FormatSpec.FormatOptions; import com.android.inputmethod.latin.makedict.FusionDictionary; import com.android.inputmethod.latin.makedict.FusionDictionary.PtNodeArray; @@ -44,9 +45,6 @@ import java.util.concurrent.TimeUnit; public final class UserHistoryDictIOUtils { private static final String TAG = UserHistoryDictIOUtils.class.getSimpleName(); private static final boolean DEBUG = false; - private static final String USES_FORGETTING_CURVE_KEY = "USES_FORGETTING_CURVE"; - private static final String USES_FORGETTING_CURVE_VALUE = "1"; - private static final String DATE_KEY = "date"; public interface OnAddWordListener { /** @@ -75,8 +73,9 @@ public final class UserHistoryDictIOUtils { final BigramDictionaryInterface dict, final UserHistoryDictionaryBigramList bigrams, final FormatOptions formatOptions, final HashMap<String, String> options) { final FusionDictionary fusionDict = constructFusionDictionary(dict, bigrams, options); - fusionDict.addOptionAttribute(USES_FORGETTING_CURVE_KEY, USES_FORGETTING_CURVE_VALUE); - fusionDict.addOptionAttribute(DATE_KEY, + fusionDict.addOptionAttribute(FormatSpec.FileHeader.USES_FORGETTING_CURVE_KEY, + FormatSpec.FileHeader.ATTRIBUTE_VALUE_TRUE); + fusionDict.addOptionAttribute(FormatSpec.FileHeader.DICTIONARY_DATE_KEY, String.valueOf(TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis()))); try { dictEncoder.writeDictionary(fusionDict, formatOptions); diff --git a/tests/src/com/android/inputmethod/latin/BinaryDictionaryDecayingTests.java b/tests/src/com/android/inputmethod/latin/BinaryDictionaryDecayingTests.java index c42765633c3e82be320796fd21e91e25447f141a..343ab420c904058627d7f3bf2505d0d480fbfb22 100644 --- a/tests/src/com/android/inputmethod/latin/BinaryDictionaryDecayingTests.java +++ b/tests/src/com/android/inputmethod/latin/BinaryDictionaryDecayingTests.java @@ -102,13 +102,13 @@ public class BinaryDictionaryDecayingTests extends AndroidTestCase { getContext().getCacheDir()); FileUtils.deleteRecursively(file); Map<String, String> attributeMap = new HashMap<String, String>(); - attributeMap.put(FormatSpec.FileHeader.DICTIONARY_ID_ATTRIBUTE, dictId); - attributeMap.put(FormatSpec.FileHeader.DICTIONARY_LOCALE_ATTRIBUTE, dictId); - attributeMap.put(FormatSpec.FileHeader.DICTIONARY_VERSION_ATTRIBUTE, + attributeMap.put(FormatSpec.FileHeader.DICTIONARY_ID_KEY, dictId); + attributeMap.put(FormatSpec.FileHeader.DICTIONARY_LOCALE_KEY, dictId); + attributeMap.put(FormatSpec.FileHeader.DICTIONARY_VERSION_KEY, String.valueOf(TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis()))); - attributeMap.put(FormatSpec.FileHeader.USES_FORGETTING_CURVE_ATTRIBUTE, + attributeMap.put(FormatSpec.FileHeader.USES_FORGETTING_CURVE_KEY, FormatSpec.FileHeader.ATTRIBUTE_VALUE_TRUE); - attributeMap.put(FormatSpec.FileHeader.HAS_HISTORICAL_INFO_ATTRIBUTE, + attributeMap.put(FormatSpec.FileHeader.HAS_HISTORICAL_INFO_KEY, FormatSpec.FileHeader.ATTRIBUTE_VALUE_TRUE); if (BinaryDictionary.createEmptyDictFile(file.getAbsolutePath(), FormatSpec.VERSION4, attributeMap)) { diff --git a/tests/src/com/android/inputmethod/latin/makedict/BinaryDictUtils.java b/tests/src/com/android/inputmethod/latin/makedict/BinaryDictUtils.java index f175968655a74a3b441580cc7318c3db53ec58a5..20cf9a56299a645a9c435485be3d79557dd1be70 100644 --- a/tests/src/com/android/inputmethod/latin/makedict/BinaryDictUtils.java +++ b/tests/src/com/android/inputmethod/latin/makedict/BinaryDictUtils.java @@ -39,13 +39,13 @@ public class BinaryDictUtils { public static DictionaryOptions makeDictionaryOptions(final String id, final String version, final FormatSpec.FormatOptions formatOptions) { final DictionaryOptions options = new DictionaryOptions(new HashMap<String, String>()); - options.mAttributes.put(FileHeader.DICTIONARY_LOCALE_ATTRIBUTE, "en_US"); - options.mAttributes.put(FileHeader.DICTIONARY_ID_ATTRIBUTE, id); - options.mAttributes.put(FileHeader.DICTIONARY_VERSION_ATTRIBUTE, version); + options.mAttributes.put(FileHeader.DICTIONARY_LOCALE_KEY, "en_US"); + options.mAttributes.put(FileHeader.DICTIONARY_ID_KEY, id); + options.mAttributes.put(FileHeader.DICTIONARY_VERSION_KEY, version); if (formatOptions.mHasTimestamp) { - options.mAttributes.put(FileHeader.HAS_HISTORICAL_INFO_ATTRIBUTE, + options.mAttributes.put(FileHeader.HAS_HISTORICAL_INFO_KEY, FileHeader.ATTRIBUTE_VALUE_TRUE); - options.mAttributes.put(FileHeader.USES_FORGETTING_CURVE_ATTRIBUTE, + options.mAttributes.put(FileHeader.USES_FORGETTING_CURVE_KEY, FileHeader.ATTRIBUTE_VALUE_TRUE); } return options; diff --git a/tests/src/com/android/inputmethod/latin/utils/UserHistoryDictIOUtilsTests.java b/tests/src/com/android/inputmethod/latin/utils/UserHistoryDictIOUtilsTests.java index ae08b49d7b2112952a28196b8a52286a70a66062..93731b3cd86c2c9d322bb687bdfa5a028553456e 100644 --- a/tests/src/com/android/inputmethod/latin/utils/UserHistoryDictIOUtilsTests.java +++ b/tests/src/com/android/inputmethod/latin/utils/UserHistoryDictIOUtilsTests.java @@ -56,9 +56,9 @@ public class UserHistoryDictIOUtilsTests extends AndroidTestCase private static final String TEST_DICT_FILE_EXTENSION = ".testDict"; private static final HashMap<String, String> HEADER_OPTIONS = new HashMap<String, String>(); static { - HEADER_OPTIONS.put(FileHeader.DICTIONARY_LOCALE_ATTRIBUTE, "en_US"); - HEADER_OPTIONS.put(FileHeader.DICTIONARY_ID_ATTRIBUTE, "test"); - HEADER_OPTIONS.put(FileHeader.DICTIONARY_VERSION_ATTRIBUTE, "1000"); + HEADER_OPTIONS.put(FileHeader.DICTIONARY_LOCALE_KEY, "en_US"); + HEADER_OPTIONS.put(FileHeader.DICTIONARY_ID_KEY, "test"); + HEADER_OPTIONS.put(FileHeader.DICTIONARY_VERSION_KEY, "1000"); } /** diff --git a/tools/dicttool/tests/com/android/inputmethod/latin/dicttool/BinaryDictOffdeviceUtilsTests.java b/tools/dicttool/tests/com/android/inputmethod/latin/dicttool/BinaryDictOffdeviceUtilsTests.java index 0c11f868efc35be6ebb7bce897174bb22210e84c..d8059e428ee02995d91da44877cf730a83b918b8 100644 --- a/tools/dicttool/tests/com/android/inputmethod/latin/dicttool/BinaryDictOffdeviceUtilsTests.java +++ b/tools/dicttool/tests/com/android/inputmethod/latin/dicttool/BinaryDictOffdeviceUtilsTests.java @@ -48,9 +48,9 @@ public class BinaryDictOffdeviceUtilsTests extends TestCase { // Create a thrice-compressed dictionary file. final DictionaryOptions testOptions = new DictionaryOptions(new HashMap<String, String>()); - testOptions.mAttributes.put(FormatSpec.FileHeader.DICTIONARY_VERSION_ATTRIBUTE, VERSION); - testOptions.mAttributes.put(FormatSpec.FileHeader.DICTIONARY_LOCALE_ATTRIBUTE, LOCALE); - testOptions.mAttributes.put(FormatSpec.FileHeader.DICTIONARY_ID_ATTRIBUTE, ID); + testOptions.mAttributes.put(FormatSpec.FileHeader.DICTIONARY_VERSION_KEY, VERSION); + testOptions.mAttributes.put(FormatSpec.FileHeader.DICTIONARY_LOCALE_KEY, LOCALE); + testOptions.mAttributes.put(FormatSpec.FileHeader.DICTIONARY_ID_KEY, ID); final FusionDictionary dict = new FusionDictionary(new PtNodeArray(), testOptions); dict.add("foo", TEST_FREQ, null, false /* isNotAWord */); dict.add("fta", 1, null, false /* isNotAWord */); @@ -80,11 +80,11 @@ public class BinaryDictOffdeviceUtilsTests extends TestCase { null /* dict : an optional dictionary to add words to, or null */, false /* deleteDictIfBroken */); assertEquals("Wrong version attribute", VERSION, resultDict.mOptions.mAttributes.get( - FormatSpec.FileHeader.DICTIONARY_VERSION_ATTRIBUTE)); + FormatSpec.FileHeader.DICTIONARY_VERSION_KEY)); assertEquals("Wrong locale attribute", LOCALE, resultDict.mOptions.mAttributes.get( - FormatSpec.FileHeader.DICTIONARY_LOCALE_ATTRIBUTE)); + FormatSpec.FileHeader.DICTIONARY_LOCALE_KEY)); assertEquals("Wrong id attribute", ID, resultDict.mOptions.mAttributes.get( - FormatSpec.FileHeader.DICTIONARY_ID_ATTRIBUTE)); + FormatSpec.FileHeader.DICTIONARY_ID_KEY)); assertEquals("Dictionary can't be read back correctly", FusionDictionary.findWordInTree(resultDict.mRootNodeArray, "foo").getFrequency(), TEST_FREQ);