Loading java/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderUtils.java +1 −1 Original line number Diff line number Diff line Loading @@ -323,7 +323,7 @@ public final class BinaryDictDecoderUtils { /** * Reads and returns the PtNode count out of a buffer and forwards the pointer. */ public static int readPtNodeCount(final DictBuffer dictBuffer) { /* package */ static int readPtNodeCount(final DictBuffer dictBuffer) { final int msb = dictBuffer.readUnsignedByte(); if (FormatSpec.MAX_PTNODES_FOR_ONE_BYTE_PTNODE_COUNT >= msb) { return msb; Loading java/src/com/android/inputmethod/latin/makedict/BinaryDictIOUtils.java +1 −1 Original line number Diff line number Diff line Loading @@ -169,7 +169,7 @@ public final class BinaryDictIOUtils { * @throws UnsupportedFormatException if the format of the file is not recognized. */ @UsedForTesting public static int getTerminalPosition(final Ver3DictDecoder dictDecoder, /* package */ static int getTerminalPosition(final Ver3DictDecoder dictDecoder, final String word) throws IOException, UnsupportedFormatException { final DictBuffer dictBuffer = dictDecoder.getDictBuffer(); if (word == null) return FormatSpec.NOT_VALID_WORD; Loading java/src/com/android/inputmethod/latin/makedict/DictDecoder.java +13 −0 Original line number Diff line number Diff line Loading @@ -58,6 +58,19 @@ public interface DictDecoder { public FusionDictionary readDictionaryBinary(final FusionDictionary dict) throws FileNotFoundException, IOException, UnsupportedFormatException; /** * Gets the address of the last PtNode of the exact matching word in the dictionary. * If no match is found, returns NOT_VALID_WORD. * * @param word the word we search for. * @return the address of the terminal node. * @throws IOException if the file can't be read. * @throws UnsupportedFormatException if the format of the file is not recognized. */ @UsedForTesting public int getTerminalPosition(final String word) throws IOException, UnsupportedFormatException; // Flags for DictionaryBufferFactory. public static final int USE_READONLY_BYTEBUFFER = 0x01000000; public static final int USE_BYTEARRAY = 0x02000000; Loading java/src/com/android/inputmethod/latin/makedict/DynamicBinaryDictIOUtils.java +2 −2 Original line number Diff line number Diff line Loading @@ -60,7 +60,7 @@ public final class DynamicBinaryDictIOUtils { final DictBuffer dictBuffer = dictDecoder.getDictBuffer(); dictBuffer.position(0); final FileHeader header = dictDecoder.readHeader(); final int wordPosition = BinaryDictIOUtils.getTerminalPosition(dictDecoder, word); final int wordPosition = dictDecoder.getTerminalPosition(word); if (wordPosition == FormatSpec.NOT_VALID_WORD) return; dictBuffer.position(wordPosition); Loading Loading @@ -263,7 +263,7 @@ public final class DynamicBinaryDictIOUtils { final DictBuffer dictBuffer = dictDecoder.getDictBuffer(); if (bigramStrings != null) { for (final WeightedString bigram : bigramStrings) { int position = BinaryDictIOUtils.getTerminalPosition(dictDecoder, bigram.mWord); int position = dictDecoder.getTerminalPosition(bigram.mWord); if (position == FormatSpec.NOT_VALID_WORD) { // TODO: figure out what is the correct thing to do here. } else { Loading java/src/com/android/inputmethod/latin/makedict/Ver3DictDecoder.java +8 −0 Original line number Diff line number Diff line Loading @@ -309,4 +309,12 @@ public class Ver3DictDecoder implements DictDecoder { } return BinaryDictDecoderUtils.readDictionaryBinary(this, dict); } @Override public int getTerminalPosition(String word) throws IOException, UnsupportedFormatException { if (mDictBuffer == null) { openDictBuffer(); } return BinaryDictIOUtils.getTerminalPosition(this, word); } } Loading
java/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderUtils.java +1 −1 Original line number Diff line number Diff line Loading @@ -323,7 +323,7 @@ public final class BinaryDictDecoderUtils { /** * Reads and returns the PtNode count out of a buffer and forwards the pointer. */ public static int readPtNodeCount(final DictBuffer dictBuffer) { /* package */ static int readPtNodeCount(final DictBuffer dictBuffer) { final int msb = dictBuffer.readUnsignedByte(); if (FormatSpec.MAX_PTNODES_FOR_ONE_BYTE_PTNODE_COUNT >= msb) { return msb; Loading
java/src/com/android/inputmethod/latin/makedict/BinaryDictIOUtils.java +1 −1 Original line number Diff line number Diff line Loading @@ -169,7 +169,7 @@ public final class BinaryDictIOUtils { * @throws UnsupportedFormatException if the format of the file is not recognized. */ @UsedForTesting public static int getTerminalPosition(final Ver3DictDecoder dictDecoder, /* package */ static int getTerminalPosition(final Ver3DictDecoder dictDecoder, final String word) throws IOException, UnsupportedFormatException { final DictBuffer dictBuffer = dictDecoder.getDictBuffer(); if (word == null) return FormatSpec.NOT_VALID_WORD; Loading
java/src/com/android/inputmethod/latin/makedict/DictDecoder.java +13 −0 Original line number Diff line number Diff line Loading @@ -58,6 +58,19 @@ public interface DictDecoder { public FusionDictionary readDictionaryBinary(final FusionDictionary dict) throws FileNotFoundException, IOException, UnsupportedFormatException; /** * Gets the address of the last PtNode of the exact matching word in the dictionary. * If no match is found, returns NOT_VALID_WORD. * * @param word the word we search for. * @return the address of the terminal node. * @throws IOException if the file can't be read. * @throws UnsupportedFormatException if the format of the file is not recognized. */ @UsedForTesting public int getTerminalPosition(final String word) throws IOException, UnsupportedFormatException; // Flags for DictionaryBufferFactory. public static final int USE_READONLY_BYTEBUFFER = 0x01000000; public static final int USE_BYTEARRAY = 0x02000000; Loading
java/src/com/android/inputmethod/latin/makedict/DynamicBinaryDictIOUtils.java +2 −2 Original line number Diff line number Diff line Loading @@ -60,7 +60,7 @@ public final class DynamicBinaryDictIOUtils { final DictBuffer dictBuffer = dictDecoder.getDictBuffer(); dictBuffer.position(0); final FileHeader header = dictDecoder.readHeader(); final int wordPosition = BinaryDictIOUtils.getTerminalPosition(dictDecoder, word); final int wordPosition = dictDecoder.getTerminalPosition(word); if (wordPosition == FormatSpec.NOT_VALID_WORD) return; dictBuffer.position(wordPosition); Loading Loading @@ -263,7 +263,7 @@ public final class DynamicBinaryDictIOUtils { final DictBuffer dictBuffer = dictDecoder.getDictBuffer(); if (bigramStrings != null) { for (final WeightedString bigram : bigramStrings) { int position = BinaryDictIOUtils.getTerminalPosition(dictDecoder, bigram.mWord); int position = dictDecoder.getTerminalPosition(bigram.mWord); if (position == FormatSpec.NOT_VALID_WORD) { // TODO: figure out what is the correct thing to do here. } else { Loading
java/src/com/android/inputmethod/latin/makedict/Ver3DictDecoder.java +8 −0 Original line number Diff line number Diff line Loading @@ -309,4 +309,12 @@ public class Ver3DictDecoder implements DictDecoder { } return BinaryDictDecoderUtils.readDictionaryBinary(this, dict); } @Override public int getTerminalPosition(String word) throws IOException, UnsupportedFormatException { if (mDictBuffer == null) { openDictBuffer(); } return BinaryDictIOUtils.getTerminalPosition(this, word); } }