Loading java/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderUtils.java +5 −29 Original line number Diff line number Diff line Loading @@ -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(); Loading @@ -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); } /** Loading java/src/com/android/inputmethod/latin/makedict/DictDecoder.java +4 −7 Original line number Diff line number Diff line Loading @@ -54,17 +54,14 @@ 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) public FusionDictionary readDictionaryBinary(final boolean deleteDictIfBroken) throws FileNotFoundException, IOException, UnsupportedFormatException; /** Loading java/src/com/android/inputmethod/latin/makedict/Ver2DictDecoder.java +2 −3 Original line number Diff line number Diff line Loading @@ -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()) { Loading java/src/com/android/inputmethod/latin/makedict/Ver4DictDecoder.java +2 −3 Original line number Diff line number Diff line Loading @@ -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(); Loading tests/src/com/android/inputmethod/latin/BinaryDictionaryDecayingTests.java +2 −2 Original line number Diff line number Diff line Loading @@ -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()); Loading Loading
java/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderUtils.java +5 −29 Original line number Diff line number Diff line Loading @@ -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(); Loading @@ -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); } /** Loading
java/src/com/android/inputmethod/latin/makedict/DictDecoder.java +4 −7 Original line number Diff line number Diff line Loading @@ -54,17 +54,14 @@ 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) public FusionDictionary readDictionaryBinary(final boolean deleteDictIfBroken) throws FileNotFoundException, IOException, UnsupportedFormatException; /** Loading
java/src/com/android/inputmethod/latin/makedict/Ver2DictDecoder.java +2 −3 Original line number Diff line number Diff line Loading @@ -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()) { Loading
java/src/com/android/inputmethod/latin/makedict/Ver4DictDecoder.java +2 −3 Original line number Diff line number Diff line Loading @@ -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(); Loading
tests/src/com/android/inputmethod/latin/BinaryDictionaryDecayingTests.java +2 −2 Original line number Diff line number Diff line Loading @@ -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()); Loading