am 328755ee
: Merge "Move FormatOptions and FileHeader to FormatSpec." into jb-mr1-dev
* commit '328755eee2f6e44daa98a54bd0ee9c0f433c58be': Move FormatOptions and FileHeader to FormatSpec.
This commit is contained in:
commit
63eef1890d
7 changed files with 47 additions and 43 deletions
|
@ -21,6 +21,7 @@ import android.util.Log;
|
|||
import com.android.inputmethod.keyboard.ProximityInfo;
|
||||
import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo;
|
||||
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.Node;
|
||||
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 static final int BINARY_DICT_VERSION = 1;
|
||||
private static final BinaryDictInputOutput.FormatOptions FORMAT_OPTIONS =
|
||||
new BinaryDictInputOutput.FormatOptions(BINARY_DICT_VERSION);
|
||||
private static final FormatSpec.FormatOptions FORMAT_OPTIONS =
|
||||
new FormatSpec.FormatOptions(BINARY_DICT_VERSION);
|
||||
|
||||
/**
|
||||
* Abstract method for loading the unigrams and bigrams of a given dictionary in a background
|
||||
|
|
|
@ -19,8 +19,8 @@ package com.android.inputmethod.latin;
|
|||
import android.util.Log;
|
||||
|
||||
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.FormatSpec.FormatOptions;
|
||||
import com.android.inputmethod.latin.makedict.FusionDictionary;
|
||||
import com.android.inputmethod.latin.makedict.FusionDictionary.Node;
|
||||
import com.android.inputmethod.latin.makedict.PendingAttribute;
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
|
||||
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.DictionaryOptions;
|
||||
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.
|
||||
*/
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
package com.android.inputmethod.latin.makedict;
|
||||
|
||||
import com.android.inputmethod.latin.Constants;
|
||||
import com.android.inputmethod.latin.makedict.FusionDictionary.DictionaryOptions;
|
||||
|
||||
/**
|
||||
* Dictionary File Format Specification.
|
||||
|
@ -194,6 +195,40 @@ public final class FormatSpec {
|
|||
static final int MAX_TERMINAL_FREQUENCY = 255;
|
||||
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() {
|
||||
// This utility class is not publicly instantiable.
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@ package com.android.inputmethod.latin;
|
|||
import com.android.inputmethod.latin.UserHistoryDictIOUtils.BigramDictionaryInterface;
|
||||
import com.android.inputmethod.latin.UserHistoryDictIOUtils.OnAddWordListener;
|
||||
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.CharGroup;
|
||||
|
||||
|
@ -45,8 +46,7 @@ public class UserHistoryDictIOUtilsTests extends AndroidTestCase
|
|||
private static final int UNIGRAM_FREQUENCY = 50;
|
||||
private static final int BIGRAM_FREQUENCY = 100;
|
||||
private static final ArrayList<String> NOT_HAVE_BIGRAM = new ArrayList<String>();
|
||||
private static final BinaryDictInputOutput.FormatOptions FORMAT_OPTIONS =
|
||||
new BinaryDictInputOutput.FormatOptions(2);
|
||||
private static final FormatSpec.FormatOptions FORMAT_OPTIONS = new FormatSpec.FormatOptions(2);
|
||||
|
||||
/**
|
||||
* Return same frequency for all words and bigrams
|
||||
|
|
|
@ -19,6 +19,7 @@ package com.android.inputmethod.latin.makedict;
|
|||
import com.android.inputmethod.latin.CollectionUtils;
|
||||
import com.android.inputmethod.latin.UserHistoryDictIOUtils;
|
||||
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.Node;
|
||||
import com.android.inputmethod.latin.makedict.FusionDictionary.WeightedString;
|
||||
|
@ -62,8 +63,7 @@ public class BinaryDictIOTests extends AndroidTestCase {
|
|||
private static final SparseArray<List<Integer>> sChainBigrams =
|
||||
CollectionUtils.newSparseArray();
|
||||
|
||||
private static final BinaryDictInputOutput.FormatOptions VERSION2 =
|
||||
new BinaryDictInputOutput.FormatOptions(2);
|
||||
private static final FormatSpec.FormatOptions VERSION2 = new FormatSpec.FormatOptions(2);
|
||||
|
||||
private static final String[] CHARACTERS = {
|
||||
"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m",
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
package com.android.inputmethod.latin.dicttool;
|
||||
|
||||
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.MakedictLog;
|
||||
import com.android.inputmethod.latin.makedict.UnsupportedFormatException;
|
||||
|
@ -311,8 +312,7 @@ public class DictionaryMaker {
|
|||
final FusionDictionary dict, final int version)
|
||||
throws FileNotFoundException, IOException, UnsupportedFormatException {
|
||||
final File outputFile = new File(outputFilename);
|
||||
final BinaryDictInputOutput.FormatOptions formatOptions =
|
||||
new BinaryDictInputOutput.FormatOptions(version);
|
||||
final FormatSpec.FormatOptions formatOptions = new FormatSpec.FormatOptions(version);
|
||||
BinaryDictInputOutput.writeDictionaryBinary(new FileOutputStream(outputFilename), dict,
|
||||
formatOptions);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue