From d2579c4832325bb703e275674706886dce50915d Mon Sep 17 00:00:00 2001 From: Yuichiro Hanada Date: Fri, 5 Oct 2012 11:43:21 +0900 Subject: fix writeCharGroup. Change-Id: Ib841afaba0a20c3b300eb7d3e9133243f9f3ae58 --- .../latin/makedict/BinaryDictIOUtils.java | 29 +++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) (limited to 'java/src') 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; + } } -- cgit v1.2.3-83-g751a