diff --git a/java/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderUtils.java b/java/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderUtils.java index fc5788de95281c4c1dc5f57e58c1982118c8502b..845299c99d7d989525004ef029e3dabee70f5433 100644 --- a/java/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderUtils.java +++ b/java/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderUtils.java @@ -500,16 +500,14 @@ public final class BinaryDictDecoderUtils { * Reads a buffer and returns the memory representation of the dictionary. * * This high-level method takes a buffer and reads its contents, populating a - * FusionDictionary structure. The optional dict argument is an existing dictionary to - * which words from the buffer should be added. If it is null, a new dictionary is created. + * FusionDictionary structure. * * @param dictDecoder the dict decoder. - * @param dict an optional dictionary to add words to, or null. - * @return the created (or merged) dictionary. + * @return the created dictionary. */ @UsedForTesting - /* package */ static FusionDictionary readDictionaryBinary(final DictDecoder dictDecoder, - final FusionDictionary dict) throws IOException, UnsupportedFormatException { + /* package */ static FusionDictionary readDictionaryBinary(final DictDecoder dictDecoder) + throws IOException, UnsupportedFormatException { // Read header final DictionaryHeader fileHeader = dictDecoder.readHeader(); @@ -517,29 +515,7 @@ public final class BinaryDictDecoderUtils { Map<Integer, PtNode> reversePtNodeMapping = new TreeMap<Integer, PtNode>(); final PtNodeArray root = readNodeArray(dictDecoder, fileHeader.mBodyOffset, reverseNodeArrayMapping, reversePtNodeMapping, fileHeader.mFormatOptions); - - FusionDictionary newDict = new FusionDictionary(root, fileHeader.mDictionaryOptions); - if (null != dict) { - for (final WordProperty wordProperty : dict) { - if (wordProperty.mIsBlacklistEntry) { - newDict.addBlacklistEntry(wordProperty.mWord, wordProperty.mShortcutTargets, - wordProperty.mIsNotAWord); - } else { - newDict.add(wordProperty.mWord, wordProperty.mProbabilityInfo, - wordProperty.mShortcutTargets, wordProperty.mIsNotAWord); - } - } - for (final WordProperty wordProperty : dict) { - // By construction a binary dictionary may not have bigrams pointing to - // words that are not also registered as unigrams so we don't have to avoid - // them explicitly here. - for (final WeightedString bigram : wordProperty.mBigrams) { - newDict.setBigram(wordProperty.mWord, bigram.mWord, bigram.mProbabilityInfo); - } - } - } - - return newDict; + return new FusionDictionary(root, fileHeader.mDictionaryOptions); } /** diff --git a/java/src/com/android/inputmethod/latin/makedict/DictDecoder.java b/java/src/com/android/inputmethod/latin/makedict/DictDecoder.java index a93a8bbad0861c8fbfb55947e9ef540aeeeb1062..0fb98aba9bb9755f77c616fc769ba0b86194a7cc 100644 --- a/java/src/com/android/inputmethod/latin/makedict/DictDecoder.java +++ b/java/src/com/android/inputmethod/latin/makedict/DictDecoder.java @@ -54,18 +54,15 @@ public interface DictDecoder { * Reads a buffer and returns the memory representation of the dictionary. * * This high-level method takes a buffer and reads its contents, populating a - * FusionDictionary structure. The optional dict argument is an existing dictionary to - * which words from the buffer should be added. If it is null, a new dictionary is created. + * FusionDictionary structure. * - * @param dict an optional dictionary to add words to, or null. * @param deleteDictIfBroken a flag indicating whether this method should remove the broken * dictionary or not. - * @return the created (or merged) dictionary. + * @return the created dictionary. */ @UsedForTesting - public FusionDictionary readDictionaryBinary(final FusionDictionary dict, - final boolean deleteDictIfBroken) - throws FileNotFoundException, IOException, UnsupportedFormatException; + public FusionDictionary readDictionaryBinary(final boolean deleteDictIfBroken) + throws FileNotFoundException, IOException, UnsupportedFormatException; /** * Gets the address of the last PtNode of the exact matching word in the dictionary. diff --git a/java/src/com/android/inputmethod/latin/makedict/Ver2DictDecoder.java b/java/src/com/android/inputmethod/latin/makedict/Ver2DictDecoder.java index fd6138d41a8d5f69d5ea4313d1cb79c2cd7d4519..5dda715a6951839afa0627d400eb98f76c645abb 100644 --- a/java/src/com/android/inputmethod/latin/makedict/Ver2DictDecoder.java +++ b/java/src/com/android/inputmethod/latin/makedict/Ver2DictDecoder.java @@ -236,14 +236,13 @@ public class Ver2DictDecoder extends AbstractDictDecoder { } @Override - public FusionDictionary readDictionaryBinary(final FusionDictionary dict, - final boolean deleteDictIfBroken) + public FusionDictionary readDictionaryBinary(final boolean deleteDictIfBroken) throws FileNotFoundException, IOException, UnsupportedFormatException { if (mDictBuffer == null) { openDictBuffer(); } try { - return BinaryDictDecoderUtils.readDictionaryBinary(this, dict); + return BinaryDictDecoderUtils.readDictionaryBinary(this); } catch (IOException e) { Log.e(TAG, "The dictionary " + mDictionaryBinaryFile.getName() + " is broken.", e); if (deleteDictIfBroken && !mDictionaryBinaryFile.delete()) { diff --git a/java/src/com/android/inputmethod/latin/makedict/Ver4DictDecoder.java b/java/src/com/android/inputmethod/latin/makedict/Ver4DictDecoder.java index 1c74852feeb8bb6f1603ad18d14a38e58f3cc13d..abaf9667695b9483065d181f44da04231ebd230d 100644 --- a/java/src/com/android/inputmethod/latin/makedict/Ver4DictDecoder.java +++ b/java/src/com/android/inputmethod/latin/makedict/Ver4DictDecoder.java @@ -56,11 +56,10 @@ public class Ver4DictDecoder extends AbstractDictDecoder { } @Override - public FusionDictionary readDictionaryBinary(final FusionDictionary dict, - final boolean deleteDictIfBroken) + public FusionDictionary readDictionaryBinary(final boolean deleteDictIfBroken) throws FileNotFoundException, IOException, UnsupportedFormatException { final DictionaryHeader header = readHeader(); - final FusionDictionary fusionDict = dict != null ? dict : + final FusionDictionary fusionDict = new FusionDictionary(new FusionDictionary.PtNodeArray(), header.mDictionaryOptions); int token = 0; final ArrayList<WordProperty> wordProperties = CollectionUtils.newArrayList(); diff --git a/tests/src/com/android/inputmethod/latin/BinaryDictionaryDecayingTests.java b/tests/src/com/android/inputmethod/latin/BinaryDictionaryDecayingTests.java index 7d664c8251465b4f5b68c368cbc6f03a8844cf69..64b793e835c065826bfefe25324d3f1ed3ef7f8d 100644 --- a/tests/src/com/android/inputmethod/latin/BinaryDictionaryDecayingTests.java +++ b/tests/src/com/android/inputmethod/latin/BinaryDictionaryDecayingTests.java @@ -152,8 +152,8 @@ public class BinaryDictionaryDecayingTests extends AndroidTestCase { final DictDecoder dictDecoder = FormatSpec.getDictDecoder(dictFile); try { - final FusionDictionary dict = dictDecoder.readDictionaryBinary(null, - false /* deleteDictIfBroken */); + final FusionDictionary dict = + dictDecoder.readDictionaryBinary(false /* deleteDictIfBroken */); PtNode ptNode = FusionDictionary.findWordInTree(dict.mRootNodeArray, "a"); assertNotNull(ptNode); assertTrue(ptNode.isTerminal()); diff --git a/tests/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderEncoderTests.java b/tests/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderEncoderTests.java index 86f245810202c823861179777cc802af0615ed66..4fb06364f9e8ba3bc87f698fa79bab91374d6992 100644 --- a/tests/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderEncoderTests.java +++ b/tests/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderEncoderTests.java @@ -252,7 +252,7 @@ public class BinaryDictDecoderEncoderTests extends AndroidTestCase { try { final DictDecoder dictDecoder = FormatSpec.getDictDecoder(file, bufferType); now = System.currentTimeMillis(); - dict = dictDecoder.readDictionaryBinary(null, false /* deleteDictIfBroken */); + dict = dictDecoder.readDictionaryBinary(false /* deleteDictIfBroken */); diff = System.currentTimeMillis() - now; } catch (IOException e) { Log.e(TAG, "IOException while reading dictionary", e); diff --git a/tools/dicttool/src/com/android/inputmethod/latin/dicttool/BinaryDictOffdeviceUtils.java b/tools/dicttool/src/com/android/inputmethod/latin/dicttool/BinaryDictOffdeviceUtils.java index e571bc21d0bedac4f1a0c894f5a5099c5218e002..d1df81b528ddf014a97a44311b570925e9efa4d0 100644 --- a/tools/dicttool/src/com/android/inputmethod/latin/dicttool/BinaryDictOffdeviceUtils.java +++ b/tools/dicttool/src/com/android/inputmethod/latin/dicttool/BinaryDictOffdeviceUtils.java @@ -198,7 +198,7 @@ public final class BinaryDictOffdeviceUtils { System.out.println("Packaging : " + decodedSpec.describeChain()); System.out.println("Uncompressed size : " + decodedSpec.mFile.length()); } - return dictDecoder.readDictionaryBinary(null, false /* deleteDictIfBroken */); + return dictDecoder.readDictionaryBinary(false /* deleteDictIfBroken */); } } } catch (IOException e) { diff --git a/tools/dicttool/src/com/android/inputmethod/latin/dicttool/DictionaryMaker.java b/tools/dicttool/src/com/android/inputmethod/latin/dicttool/DictionaryMaker.java index 143bce5ac270186e14ce63637feca0309b2d4dd2..80d71fc64b180b8000e190e6c5f177a7fef0a83b 100644 --- a/tools/dicttool/src/com/android/inputmethod/latin/dicttool/DictionaryMaker.java +++ b/tools/dicttool/src/com/android/inputmethod/latin/dicttool/DictionaryMaker.java @@ -265,7 +265,7 @@ public class DictionaryMaker { throws FileNotFoundException, IOException, UnsupportedFormatException { final File file = new File(binaryFilename); final DictDecoder dictDecoder = FormatSpec.getDictDecoder(file); - return dictDecoder.readDictionaryBinary(null, false /* deleteDictIfBroken */); + return dictDecoder.readDictionaryBinary(false /* deleteDictIfBroken */); } /** 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 69b49f015fd8822e3e7d94bff4d11319d6b81a82..7a4f6f7c5b06ba8524d36a289a0b443b828dd1b2 100644 --- a/tools/dicttool/tests/com/android/inputmethod/latin/dicttool/BinaryDictOffdeviceUtilsTests.java +++ b/tools/dicttool/tests/com/android/inputmethod/latin/dicttool/BinaryDictOffdeviceUtilsTests.java @@ -78,9 +78,8 @@ public class BinaryDictOffdeviceUtilsTests extends TestCase { } assertEquals("Wrong decode spec", 3, decodeSpec.mDecoderSpec.size()); final DictDecoder dictDecoder = FormatSpec.getDictDecoder(decodeSpec.mFile); - final FusionDictionary resultDict = dictDecoder.readDictionaryBinary( - null /* dict : an optional dictionary to add words to, or null */, - false /* deleteDictIfBroken */); + final FusionDictionary resultDict = + dictDecoder.readDictionaryBinary(false /* deleteDictIfBroken */); assertEquals("Wrong version attribute", VERSION, resultDict.mOptions.mAttributes.get( DictionaryHeader.DICTIONARY_VERSION_KEY)); assertEquals("Wrong locale attribute", LOCALE, resultDict.mOptions.mAttributes.get(