aboutsummaryrefslogtreecommitdiffstats
path: root/java/src
diff options
context:
space:
mode:
authorKen Wakasa <kwakasa@google.com>2012-10-04 23:05:51 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2012-10-04 23:05:51 -0700
commit035b2600589fd3db5a3dd8ae2a1ca55c48bd260d (patch)
tree4908b2fada1de3fac0b757f2ba3d78f2bd7f12ad /java/src
parentddf8b9e1eae42cc76ed116517e6618a0f1dc3f31 (diff)
parentd2579c4832325bb703e275674706886dce50915d (diff)
downloadlatinime-035b2600589fd3db5a3dd8ae2a1ca55c48bd260d.tar.gz
latinime-035b2600589fd3db5a3dd8ae2a1ca55c48bd260d.tar.xz
latinime-035b2600589fd3db5a3dd8ae2a1ca55c48bd260d.zip
Merge "fix writeCharGroup."
Diffstat (limited to 'java/src')
-rw-r--r--java/src/com/android/inputmethod/latin/makedict/BinaryDictIOUtils.java29
1 files changed, 26 insertions, 3 deletions
diff --git a/java/src/com/android/inputmethod/latin/makedict/BinaryDictIOUtils.java b/java/src/com/android/inputmethod/latin/makedict/BinaryDictIOUtils.java
index e5ec449ea..40e089f3a 100644
--- a/java/src/com/android/inputmethod/latin/makedict/BinaryDictIOUtils.java
+++ b/java/src/com/android/inputmethod/latin/makedict/BinaryDictIOUtils.java
@@ -535,10 +535,13 @@ public final class BinaryDictIOUtils {
// TODO: Consolidate this code with the code that computes the size of the bigram list
// in BinaryDictionaryInputOutput#computeActualNodeSize
for (int i = 0; i < info.mBigrams.size(); ++i) {
- final int bigramOffset = info.mBigrams.get(i).mAddress - info.mOriginalAddress;
+
final int bigramFrequency = info.mBigrams.get(i).mFrequency;
int bigramFlags = (i < info.mBigrams.size() - 1)
? FormatSpec.FLAG_ATTRIBUTE_HAS_NEXT : 0;
+ size++;
+ final int bigramOffset = info.mBigrams.get(i).mAddress - (info.mOriginalAddress
+ + size);
bigramFlags |= (bigramOffset < 0) ? FormatSpec.FLAG_ATTRIBUTE_OFFSET_NEGATIVE : 0;
switch (BinaryDictInputOutput.getByteSize(bigramOffset)) {
case 1:
@@ -553,7 +556,6 @@ public final class BinaryDictIOUtils {
}
bigramFlags |= bigramFrequency & FormatSpec.FLAG_ATTRIBUTE_FREQUENCY;
destination.write((byte)bigramFlags);
- size++;
size += writeVariableAddress(destination, Math.abs(bigramOffset));
}
}
@@ -717,7 +719,7 @@ public final class BinaryDictIOUtils {
if (position == FormatSpec.NOT_VALID_WORD) {
// TODO: figure out what is the correct thing to do here.
} else {
- bigrams.add(new PendingAttribute(position, bigram.mFrequency));
+ bigrams.add(new PendingAttribute(bigram.mFrequency, position));
}
}
}
@@ -947,4 +949,25 @@ public final class BinaryDictIOUtils {
}
}
}
+
+ /**
+ * Find a word from the buffer.
+ *
+ * @param buffer the buffer representing the body of the dictionary file.
+ * @param word the word searched
+ * @return the found group
+ * @throws IOException
+ * @throws UnsupportedFormatException
+ */
+ public static CharGroupInfo findWordFromBuffer(final FusionDictionaryBufferInterface buffer,
+ final String word) throws IOException, UnsupportedFormatException {
+ int position = getTerminalPosition(buffer, word);
+ if (position != FormatSpec.NOT_VALID_WORD) {
+ buffer.position(0);
+ final FileHeader header = BinaryDictInputOutput.readHeader(buffer);
+ buffer.position(position);
+ return BinaryDictInputOutput.readCharGroup(buffer, position, header.mFormatOptions);
+ }
+ return null;
+ }
}