am bcb095e7: am e6a64022: am 676bb517: Merge "Add Ver4DictUpdater."

* commit 'bcb095e72f57df667f133e0d8d4e223045bfed70':
  Add Ver4DictUpdater.
main
Ken Wakasa 2013-10-09 20:33:26 -07:00 committed by Android Git Automerger
commit b2f59966e2
5 changed files with 65 additions and 2 deletions

View File

@ -57,7 +57,7 @@ public class Ver3DictUpdater extends Ver3DictDecoder implements DictUpdater {
public void deleteWord(final String word) throws IOException, UnsupportedFormatException { public void deleteWord(final String word) throws IOException, UnsupportedFormatException {
if (mOutStream == null) openStreamAndBuffer(); if (mOutStream == null) openStreamAndBuffer();
mDictBuffer.position(0); mDictBuffer.position(0);
super.readHeader(); readHeader();
final int wordPos = getTerminalPosition(word); final int wordPos = getTerminalPosition(word);
if (wordPos != FormatSpec.NOT_VALID_WORD) { if (wordPos != FormatSpec.NOT_VALID_WORD) {
mDictBuffer.position(wordPos); mDictBuffer.position(wordPos);

View File

@ -48,7 +48,7 @@ public class Ver4DictDecoder extends AbstractDictDecoder {
private final File mDictDirectory; private final File mDictDirectory;
private final DictionaryBufferFactory mBufferFactory; private final DictionaryBufferFactory mBufferFactory;
private DictBuffer mDictBuffer; protected DictBuffer mDictBuffer;
private DictBuffer mFrequencyBuffer; private DictBuffer mFrequencyBuffer;
private DictBuffer mTerminalAddressTableBuffer; private DictBuffer mTerminalAddressTableBuffer;
private DictBuffer mBigramBuffer; private DictBuffer mBigramBuffer;

View File

@ -0,0 +1,59 @@
/*
* Copyright (C) 2013 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.inputmethod.latin.makedict;
import com.android.inputmethod.annotations.UsedForTesting;
import com.android.inputmethod.latin.makedict.FusionDictionary.WeightedString;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
/**
* An implementation of DictUpdater for version 4 binary dictionary.
*/
@UsedForTesting
public class Ver4DictUpdater extends Ver4DictDecoder implements DictUpdater {
@UsedForTesting
public Ver4DictUpdater(final File dictDirectory, final int factoryType) {
// DictUpdater must have an updatable DictBuffer.
super(dictDirectory, ((factoryType & MASK_DICTBUFFER) == USE_BYTEARRAY)
? USE_BYTEARRAY : USE_WRITABLE_BYTEBUFFER);
}
@Override
public void deleteWord(final String word) throws IOException, UnsupportedFormatException {
if (mDictBuffer == null) openDictBuffer();
readHeader();
final int wordPos = getTerminalPosition(word);
if (wordPos != FormatSpec.NOT_VALID_WORD) {
mDictBuffer.position(wordPos);
final int flags = PtNodeReader.readPtNodeOptionFlags(mDictBuffer);
mDictBuffer.position(wordPos);
mDictBuffer.put((byte) DynamicBinaryDictIOUtils.markAsDeleted(flags));
}
}
@Override
public void insertWord(final String word, final int frequency,
final ArrayList<WeightedString> bigramStrings, final ArrayList<WeightedString> shortcuts,
final boolean isNotAWord, final boolean isBlackListEntry)
throws IOException, UnsupportedFormatException {
// TODO: Implement this method.
}
}

View File

@ -660,6 +660,8 @@ public class BinaryDictDecoderEncoderTests extends AndroidTestCase {
final DictUpdater dictUpdater; final DictUpdater dictUpdater;
if (formatOptions.mVersion == 3) { if (formatOptions.mVersion == 3) {
dictUpdater = new Ver3DictUpdater(file, DictDecoder.USE_WRITABLE_BYTEBUFFER); dictUpdater = new Ver3DictUpdater(file, DictDecoder.USE_WRITABLE_BYTEBUFFER);
} else if (formatOptions.mVersion == 4) {
dictUpdater = new Ver4DictUpdater(file, DictDecoder.USE_WRITABLE_BYTEBUFFER);
} else { } else {
throw new RuntimeException("DictUpdater for version " + formatOptions.mVersion throw new RuntimeException("DictUpdater for version " + formatOptions.mVersion
+ " doesn't exist."); + " doesn't exist.");
@ -684,5 +686,6 @@ public class BinaryDictDecoderEncoderTests extends AndroidTestCase {
public void testDeleteWord() { public void testDeleteWord() {
runTestDeleteWord(VERSION3_WITH_DYNAMIC_UPDATE); runTestDeleteWord(VERSION3_WITH_DYNAMIC_UPDATE);
runTestDeleteWord(VERSION4_WITH_DYNAMIC_UPDATE);
} }
} }

View File

@ -46,6 +46,7 @@ public class BinaryDictIOUtilsTests extends AndroidTestCase {
private static final String TEST_DICT_FILE_EXTENSION = ".testDict"; private static final String TEST_DICT_FILE_EXTENSION = ".testDict";
private static final int VERSION3 = 3; private static final int VERSION3 = 3;
private static final int VERSION4 = 4;
private static final String[] CHARACTERS = { private static final String[] CHARACTERS = {
"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m",