am 63eef189: am 328755ee: Merge "Move FormatOptions and FileHeader to FormatSpec." into jb-mr1-dev

* commit '63eef1890dfb2cc9dd5f0a59786fde64a8a90904':
  Move FormatOptions and FileHeader to FormatSpec.
main
Ken Wakasa 2012-09-13 14:11:06 -07:00 committed by Android Git Automerger
commit da5ef60c95
7 changed files with 47 additions and 43 deletions

View File

@ -21,6 +21,7 @@ import android.util.Log;
import com.android.inputmethod.keyboard.ProximityInfo; import com.android.inputmethod.keyboard.ProximityInfo;
import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo; import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo;
import com.android.inputmethod.latin.makedict.BinaryDictInputOutput; import com.android.inputmethod.latin.makedict.BinaryDictInputOutput;
import com.android.inputmethod.latin.makedict.FormatSpec;
import com.android.inputmethod.latin.makedict.FusionDictionary; import com.android.inputmethod.latin.makedict.FusionDictionary;
import com.android.inputmethod.latin.makedict.FusionDictionary.Node; import com.android.inputmethod.latin.makedict.FusionDictionary.Node;
import com.android.inputmethod.latin.makedict.FusionDictionary.WeightedString; import com.android.inputmethod.latin.makedict.FusionDictionary.WeightedString;
@ -90,8 +91,8 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
private final DictionaryController mLocalDictionaryController = new DictionaryController(); private final DictionaryController mLocalDictionaryController = new DictionaryController();
private static final int BINARY_DICT_VERSION = 1; private static final int BINARY_DICT_VERSION = 1;
private static final BinaryDictInputOutput.FormatOptions FORMAT_OPTIONS = private static final FormatSpec.FormatOptions FORMAT_OPTIONS =
new BinaryDictInputOutput.FormatOptions(BINARY_DICT_VERSION); new FormatSpec.FormatOptions(BINARY_DICT_VERSION);
/** /**
* Abstract method for loading the unigrams and bigrams of a given dictionary in a background * Abstract method for loading the unigrams and bigrams of a given dictionary in a background

View File

@ -19,8 +19,8 @@ package com.android.inputmethod.latin;
import android.util.Log; import android.util.Log;
import com.android.inputmethod.latin.makedict.BinaryDictInputOutput; import com.android.inputmethod.latin.makedict.BinaryDictInputOutput;
import com.android.inputmethod.latin.makedict.BinaryDictInputOutput.FormatOptions;
import com.android.inputmethod.latin.makedict.BinaryDictInputOutput.FusionDictionaryBufferInterface; import com.android.inputmethod.latin.makedict.BinaryDictInputOutput.FusionDictionaryBufferInterface;
import com.android.inputmethod.latin.makedict.FormatSpec.FormatOptions;
import com.android.inputmethod.latin.makedict.FusionDictionary; import com.android.inputmethod.latin.makedict.FusionDictionary;
import com.android.inputmethod.latin.makedict.FusionDictionary.Node; import com.android.inputmethod.latin.makedict.FusionDictionary.Node;
import com.android.inputmethod.latin.makedict.PendingAttribute; import com.android.inputmethod.latin.makedict.PendingAttribute;

View File

@ -16,6 +16,8 @@
package com.android.inputmethod.latin.makedict; package com.android.inputmethod.latin.makedict;
import com.android.inputmethod.latin.makedict.FormatSpec.FileHeader;
import com.android.inputmethod.latin.makedict.FormatSpec.FormatOptions;
import com.android.inputmethod.latin.makedict.FusionDictionary.CharGroup; import com.android.inputmethod.latin.makedict.FusionDictionary.CharGroup;
import com.android.inputmethod.latin.makedict.FusionDictionary.DictionaryOptions; import com.android.inputmethod.latin.makedict.FusionDictionary.DictionaryOptions;
import com.android.inputmethod.latin.makedict.FusionDictionary.Node; import com.android.inputmethod.latin.makedict.FusionDictionary.Node;
@ -107,40 +109,6 @@ public class BinaryDictInputOutput {
} }
} }
/**
* Options about file format.
*/
public static class FormatOptions {
public final int mVersion;
public final boolean mHasParentAddress;
public FormatOptions(final int version) {
this(version, false);
}
public FormatOptions(final int version, final boolean hasParentAddress) {
mVersion = version;
if (version < FormatSpec.FIRST_VERSION_WITH_PARENT_ADDRESS && hasParentAddress) {
throw new RuntimeException("Parent addresses are only supported with versions "
+ FormatSpec.FIRST_VERSION_WITH_PARENT_ADDRESS + " and ulterior.");
}
mHasParentAddress = hasParentAddress;
}
}
/**
* Class representing file header.
*/
private static final class FileHeader {
public final int mHeaderSize;
public final DictionaryOptions mDictionaryOptions;
public final FormatOptions mFormatOptions;
public FileHeader(final int headerSize, final DictionaryOptions dictionaryOptions,
final FormatOptions formatOptions) {
mHeaderSize = headerSize;
mDictionaryOptions = dictionaryOptions;
mFormatOptions = formatOptions;
}
}
/** /**
* A class grouping utility function for our specific character encoding. * A class grouping utility function for our specific character encoding.
*/ */

View File

@ -17,6 +17,7 @@
package com.android.inputmethod.latin.makedict; package com.android.inputmethod.latin.makedict;
import com.android.inputmethod.latin.Constants; import com.android.inputmethod.latin.Constants;
import com.android.inputmethod.latin.makedict.FusionDictionary.DictionaryOptions;
/** /**
* Dictionary File Format Specification. * Dictionary File Format Specification.
@ -194,6 +195,40 @@ public final class FormatSpec {
static final int MAX_TERMINAL_FREQUENCY = 255; static final int MAX_TERMINAL_FREQUENCY = 255;
static final int MAX_BIGRAM_FREQUENCY = 15; static final int MAX_BIGRAM_FREQUENCY = 15;
/**
* Options about file format.
*/
public static class FormatOptions {
public final int mVersion;
public final boolean mHasParentAddress;
public FormatOptions(final int version) {
this(version, false);
}
public FormatOptions(final int version, final boolean hasParentAddress) {
mVersion = version;
if (version < FormatSpec.FIRST_VERSION_WITH_PARENT_ADDRESS && hasParentAddress) {
throw new RuntimeException("Parent addresses are only supported with versions "
+ FormatSpec.FIRST_VERSION_WITH_PARENT_ADDRESS + " and ulterior.");
}
mHasParentAddress = hasParentAddress;
}
}
/**
* Class representing file header.
*/
static final class FileHeader {
public final int mHeaderSize;
public final DictionaryOptions mDictionaryOptions;
public final FormatOptions mFormatOptions;
public FileHeader(final int headerSize, final DictionaryOptions dictionaryOptions,
final FormatOptions formatOptions) {
mHeaderSize = headerSize;
mDictionaryOptions = dictionaryOptions;
mFormatOptions = formatOptions;
}
}
private FormatSpec() { private FormatSpec() {
// This utility class is not publicly instantiable. // This utility class is not publicly instantiable.
} }

View File

@ -19,6 +19,7 @@ package com.android.inputmethod.latin;
import com.android.inputmethod.latin.UserHistoryDictIOUtils.BigramDictionaryInterface; import com.android.inputmethod.latin.UserHistoryDictIOUtils.BigramDictionaryInterface;
import com.android.inputmethod.latin.UserHistoryDictIOUtils.OnAddWordListener; import com.android.inputmethod.latin.UserHistoryDictIOUtils.OnAddWordListener;
import com.android.inputmethod.latin.makedict.BinaryDictInputOutput; import com.android.inputmethod.latin.makedict.BinaryDictInputOutput;
import com.android.inputmethod.latin.makedict.FormatSpec;
import com.android.inputmethod.latin.makedict.FusionDictionary; import com.android.inputmethod.latin.makedict.FusionDictionary;
import com.android.inputmethod.latin.makedict.FusionDictionary.CharGroup; import com.android.inputmethod.latin.makedict.FusionDictionary.CharGroup;
@ -45,8 +46,7 @@ public class UserHistoryDictIOUtilsTests extends AndroidTestCase
private static final int UNIGRAM_FREQUENCY = 50; private static final int UNIGRAM_FREQUENCY = 50;
private static final int BIGRAM_FREQUENCY = 100; private static final int BIGRAM_FREQUENCY = 100;
private static final ArrayList<String> NOT_HAVE_BIGRAM = new ArrayList<String>(); private static final ArrayList<String> NOT_HAVE_BIGRAM = new ArrayList<String>();
private static final BinaryDictInputOutput.FormatOptions FORMAT_OPTIONS = private static final FormatSpec.FormatOptions FORMAT_OPTIONS = new FormatSpec.FormatOptions(2);
new BinaryDictInputOutput.FormatOptions(2);
/** /**
* Return same frequency for all words and bigrams * Return same frequency for all words and bigrams

View File

@ -19,6 +19,7 @@ package com.android.inputmethod.latin.makedict;
import com.android.inputmethod.latin.CollectionUtils; import com.android.inputmethod.latin.CollectionUtils;
import com.android.inputmethod.latin.UserHistoryDictIOUtils; import com.android.inputmethod.latin.UserHistoryDictIOUtils;
import com.android.inputmethod.latin.makedict.BinaryDictInputOutput.FusionDictionaryBufferInterface; import com.android.inputmethod.latin.makedict.BinaryDictInputOutput.FusionDictionaryBufferInterface;
import com.android.inputmethod.latin.makedict.FormatSpec;
import com.android.inputmethod.latin.makedict.FusionDictionary.CharGroup; import com.android.inputmethod.latin.makedict.FusionDictionary.CharGroup;
import com.android.inputmethod.latin.makedict.FusionDictionary.Node; import com.android.inputmethod.latin.makedict.FusionDictionary.Node;
import com.android.inputmethod.latin.makedict.FusionDictionary.WeightedString; import com.android.inputmethod.latin.makedict.FusionDictionary.WeightedString;
@ -62,8 +63,7 @@ public class BinaryDictIOTests extends AndroidTestCase {
private static final SparseArray<List<Integer>> sChainBigrams = private static final SparseArray<List<Integer>> sChainBigrams =
CollectionUtils.newSparseArray(); CollectionUtils.newSparseArray();
private static final BinaryDictInputOutput.FormatOptions VERSION2 = private static final FormatSpec.FormatOptions VERSION2 = new FormatSpec.FormatOptions(2);
new BinaryDictInputOutput.FormatOptions(2);
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",

View File

@ -17,6 +17,7 @@
package com.android.inputmethod.latin.dicttool; package com.android.inputmethod.latin.dicttool;
import com.android.inputmethod.latin.makedict.BinaryDictInputOutput; import com.android.inputmethod.latin.makedict.BinaryDictInputOutput;
import com.android.inputmethod.latin.makedict.FormatSpec;
import com.android.inputmethod.latin.makedict.FusionDictionary; import com.android.inputmethod.latin.makedict.FusionDictionary;
import com.android.inputmethod.latin.makedict.MakedictLog; import com.android.inputmethod.latin.makedict.MakedictLog;
import com.android.inputmethod.latin.makedict.UnsupportedFormatException; import com.android.inputmethod.latin.makedict.UnsupportedFormatException;
@ -311,8 +312,7 @@ public class DictionaryMaker {
final FusionDictionary dict, final int version) final FusionDictionary dict, final int version)
throws FileNotFoundException, IOException, UnsupportedFormatException { throws FileNotFoundException, IOException, UnsupportedFormatException {
final File outputFile = new File(outputFilename); final File outputFile = new File(outputFilename);
final BinaryDictInputOutput.FormatOptions formatOptions = final FormatSpec.FormatOptions formatOptions = new FormatSpec.FormatOptions(version);
new BinaryDictInputOutput.FormatOptions(version);
BinaryDictInputOutput.writeDictionaryBinary(new FileOutputStream(outputFilename), dict, BinaryDictInputOutput.writeDictionaryBinary(new FileOutputStream(outputFilename), dict,
formatOptions); formatOptions);
} }