Merge "Version up dynamic dict format from 401 to 402."
commit
b59272c944
|
@ -114,7 +114,8 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
|
||||||
private boolean needsToMigrateDictionary(final int formatVersion) {
|
private boolean needsToMigrateDictionary(final int formatVersion) {
|
||||||
// When we bump up the dictionary format version, the old version should be added to here
|
// When we bump up the dictionary format version, the old version should be added to here
|
||||||
// for supporting migration. Note that native code has to support reading such formats.
|
// for supporting migration. Note that native code has to support reading such formats.
|
||||||
return formatVersion == FormatSpec.VERSION4_ONLY_FOR_TESTING;
|
return formatVersion == FormatSpec.VERSION4_ONLY_FOR_TESTING
|
||||||
|
|| formatVersion == FormatSpec.VERSION401;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isValidDictionaryLocked() {
|
public boolean isValidDictionaryLocked() {
|
||||||
|
|
|
@ -192,8 +192,9 @@ public final class FormatSpec {
|
||||||
public static final int VERSION2 = 2;
|
public static final int VERSION2 = 2;
|
||||||
// Dictionary version used for testing.
|
// Dictionary version used for testing.
|
||||||
public static final int VERSION4_ONLY_FOR_TESTING = 399;
|
public static final int VERSION4_ONLY_FOR_TESTING = 399;
|
||||||
public static final int VERSION4 = 401;
|
public static final int VERSION401 = 401;
|
||||||
public static final int VERSION4_DEV = 402;
|
public static final int VERSION4 = 402;
|
||||||
|
public static final int VERSION4_DEV = 403;
|
||||||
static final int MINIMUM_SUPPORTED_VERSION = VERSION2;
|
static final int MINIMUM_SUPPORTED_VERSION = VERSION2;
|
||||||
static final int MAXIMUM_SUPPORTED_VERSION = VERSION4_DEV;
|
static final int MAXIMUM_SUPPORTED_VERSION = VERSION4_DEV;
|
||||||
|
|
||||||
|
|
|
@ -139,6 +139,8 @@ class HeaderPolicy : public DictionaryHeaderStructurePolicy {
|
||||||
switch (mDictFormatVersion) {
|
switch (mDictFormatVersion) {
|
||||||
case FormatUtils::VERSION_2:
|
case FormatUtils::VERSION_2:
|
||||||
return FormatUtils::VERSION_2;
|
return FormatUtils::VERSION_2;
|
||||||
|
case FormatUtils::VERSION_401:
|
||||||
|
return FormatUtils::VERSION_401;
|
||||||
case FormatUtils::VERSION_4_ONLY_FOR_TESTING:
|
case FormatUtils::VERSION_4_ONLY_FOR_TESTING:
|
||||||
return FormatUtils::VERSION_4_ONLY_FOR_TESTING;
|
return FormatUtils::VERSION_4_ONLY_FOR_TESTING;
|
||||||
case FormatUtils::VERSION_4:
|
case FormatUtils::VERSION_4:
|
||||||
|
@ -247,7 +249,7 @@ class HeaderPolicy : public DictionaryHeaderStructurePolicy {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool supportsBeginningOfSentence() const {
|
bool supportsBeginningOfSentence() const {
|
||||||
return mDictFormatVersion == FormatUtils::VERSION_4_DEV;
|
return mDictFormatVersion > FormatUtils::VERSION_401;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -98,6 +98,7 @@ typedef DictionaryHeaderStructurePolicy::AttributeMap AttributeMap;
|
||||||
case FormatUtils::VERSION_2:
|
case FormatUtils::VERSION_2:
|
||||||
// Version 2 dictionary writing is not supported.
|
// Version 2 dictionary writing is not supported.
|
||||||
return false;
|
return false;
|
||||||
|
case FormatUtils::VERSION_401:
|
||||||
case FormatUtils::VERSION_4_ONLY_FOR_TESTING:
|
case FormatUtils::VERSION_4_ONLY_FOR_TESTING:
|
||||||
case FormatUtils::VERSION_4:
|
case FormatUtils::VERSION_4:
|
||||||
case FormatUtils::VERSION_4_DEV:
|
case FormatUtils::VERSION_4_DEV:
|
||||||
|
|
|
@ -57,13 +57,14 @@ namespace latinime {
|
||||||
const DictionaryHeaderStructurePolicy::AttributeMap *const attributeMap) {
|
const DictionaryHeaderStructurePolicy::AttributeMap *const attributeMap) {
|
||||||
FormatUtils::FORMAT_VERSION dictFormatVersion = FormatUtils::getFormatVersion(formatVersion);
|
FormatUtils::FORMAT_VERSION dictFormatVersion = FormatUtils::getFormatVersion(formatVersion);
|
||||||
switch (dictFormatVersion) {
|
switch (dictFormatVersion) {
|
||||||
case FormatUtils::VERSION_4: {
|
case FormatUtils::VERSION_401: {
|
||||||
return newPolicyForOnMemoryV4Dict<backward::v401::Ver4DictConstants,
|
return newPolicyForOnMemoryV4Dict<backward::v401::Ver4DictConstants,
|
||||||
backward::v401::Ver4DictBuffers,
|
backward::v401::Ver4DictBuffers,
|
||||||
backward::v401::Ver4DictBuffers::Ver4DictBuffersPtr,
|
backward::v401::Ver4DictBuffers::Ver4DictBuffersPtr,
|
||||||
backward::v401::Ver4PatriciaTriePolicy>(
|
backward::v401::Ver4PatriciaTriePolicy>(
|
||||||
dictFormatVersion, locale, attributeMap);
|
dictFormatVersion, locale, attributeMap);
|
||||||
}
|
}
|
||||||
|
case FormatUtils::VERSION_4:
|
||||||
case FormatUtils::VERSION_4_ONLY_FOR_TESTING:
|
case FormatUtils::VERSION_4_ONLY_FOR_TESTING:
|
||||||
case FormatUtils::VERSION_4_DEV: {
|
case FormatUtils::VERSION_4_DEV: {
|
||||||
return newPolicyForOnMemoryV4Dict<Ver4DictConstants, Ver4DictBuffers,
|
return newPolicyForOnMemoryV4Dict<Ver4DictConstants, Ver4DictBuffers,
|
||||||
|
@ -115,13 +116,14 @@ template<class DictConstants, class DictBuffers, class DictBuffersPtr, class Str
|
||||||
case FormatUtils::VERSION_2:
|
case FormatUtils::VERSION_2:
|
||||||
AKLOGE("Given path is a directory but the format is version 2. path: %s", path);
|
AKLOGE("Given path is a directory but the format is version 2. path: %s", path);
|
||||||
break;
|
break;
|
||||||
case FormatUtils::VERSION_4: {
|
case FormatUtils::VERSION_401: {
|
||||||
return newPolicyForV4Dict<backward::v401::Ver4DictConstants,
|
return newPolicyForV4Dict<backward::v401::Ver4DictConstants,
|
||||||
backward::v401::Ver4DictBuffers,
|
backward::v401::Ver4DictBuffers,
|
||||||
backward::v401::Ver4DictBuffers::Ver4DictBuffersPtr,
|
backward::v401::Ver4DictBuffers::Ver4DictBuffersPtr,
|
||||||
backward::v401::Ver4PatriciaTriePolicy>(
|
backward::v401::Ver4PatriciaTriePolicy>(
|
||||||
headerFilePath, formatVersion, std::move(mmappedBuffer));
|
headerFilePath, formatVersion, std::move(mmappedBuffer));
|
||||||
}
|
}
|
||||||
|
case FormatUtils::VERSION_4:
|
||||||
case FormatUtils::VERSION_4_ONLY_FOR_TESTING:
|
case FormatUtils::VERSION_4_ONLY_FOR_TESTING:
|
||||||
case FormatUtils::VERSION_4_DEV: {
|
case FormatUtils::VERSION_4_DEV: {
|
||||||
return newPolicyForV4Dict<Ver4DictConstants, Ver4DictBuffers,
|
return newPolicyForV4Dict<Ver4DictConstants, Ver4DictBuffers,
|
||||||
|
@ -177,6 +179,7 @@ template<class DictConstants, class DictBuffers, class DictBuffersPtr, class Str
|
||||||
case FormatUtils::VERSION_2:
|
case FormatUtils::VERSION_2:
|
||||||
return DictionaryStructureWithBufferPolicy::StructurePolicyPtr(
|
return DictionaryStructureWithBufferPolicy::StructurePolicyPtr(
|
||||||
new PatriciaTriePolicy(std::move(mmappedBuffer)));
|
new PatriciaTriePolicy(std::move(mmappedBuffer)));
|
||||||
|
case FormatUtils::VERSION_401:
|
||||||
case FormatUtils::VERSION_4_ONLY_FOR_TESTING:
|
case FormatUtils::VERSION_4_ONLY_FOR_TESTING:
|
||||||
case FormatUtils::VERSION_4:
|
case FormatUtils::VERSION_4:
|
||||||
case FormatUtils::VERSION_4_DEV:
|
case FormatUtils::VERSION_4_DEV:
|
||||||
|
|
|
@ -41,11 +41,12 @@ const char *const DictFileWritingUtils::TEMP_FILE_SUFFIX_FOR_WRITING_DICT_FILE =
|
||||||
TimeKeeper::setCurrentTime();
|
TimeKeeper::setCurrentTime();
|
||||||
const FormatUtils::FORMAT_VERSION formatVersion = FormatUtils::getFormatVersion(dictVersion);
|
const FormatUtils::FORMAT_VERSION formatVersion = FormatUtils::getFormatVersion(dictVersion);
|
||||||
switch (formatVersion) {
|
switch (formatVersion) {
|
||||||
case FormatUtils::VERSION_4:
|
case FormatUtils::VERSION_401:
|
||||||
return createEmptyV4DictFile<backward::v401::Ver4DictConstants,
|
return createEmptyV4DictFile<backward::v401::Ver4DictConstants,
|
||||||
backward::v401::Ver4DictBuffers,
|
backward::v401::Ver4DictBuffers,
|
||||||
backward::v401::Ver4DictBuffers::Ver4DictBuffersPtr>(
|
backward::v401::Ver4DictBuffers::Ver4DictBuffersPtr>(
|
||||||
filePath, localeAsCodePointVector, attributeMap, formatVersion);
|
filePath, localeAsCodePointVector, attributeMap, formatVersion);
|
||||||
|
case FormatUtils::VERSION_4:
|
||||||
case FormatUtils::VERSION_4_ONLY_FOR_TESTING:
|
case FormatUtils::VERSION_4_ONLY_FOR_TESTING:
|
||||||
case FormatUtils::VERSION_4_DEV:
|
case FormatUtils::VERSION_4_DEV:
|
||||||
return createEmptyV4DictFile<Ver4DictConstants, Ver4DictBuffers,
|
return createEmptyV4DictFile<Ver4DictConstants, Ver4DictBuffers,
|
||||||
|
|
|
@ -29,6 +29,8 @@ const int FormatUtils::DICTIONARY_MINIMUM_SIZE = 12;
|
||||||
switch (formatVersion) {
|
switch (formatVersion) {
|
||||||
case VERSION_2:
|
case VERSION_2:
|
||||||
return VERSION_2;
|
return VERSION_2;
|
||||||
|
case VERSION_401:
|
||||||
|
return VERSION_401;
|
||||||
case VERSION_4_ONLY_FOR_TESTING:
|
case VERSION_4_ONLY_FOR_TESTING:
|
||||||
return VERSION_4_ONLY_FOR_TESTING;
|
return VERSION_4_ONLY_FOR_TESTING;
|
||||||
case VERSION_4:
|
case VERSION_4:
|
||||||
|
@ -60,6 +62,8 @@ const int FormatUtils::DICTIONARY_MINIMUM_SIZE = 12;
|
||||||
// same so we use them for both here.
|
// same so we use them for both here.
|
||||||
if (ByteArrayUtils::readUint16(dict, 4) == VERSION_2) {
|
if (ByteArrayUtils::readUint16(dict, 4) == VERSION_2) {
|
||||||
return VERSION_2;
|
return VERSION_2;
|
||||||
|
} else if (ByteArrayUtils::readUint16(dict, 4) == VERSION_401) {
|
||||||
|
return VERSION_401;
|
||||||
} else if (ByteArrayUtils::readUint16(dict, 4) == VERSION_4_ONLY_FOR_TESTING) {
|
} else if (ByteArrayUtils::readUint16(dict, 4) == VERSION_4_ONLY_FOR_TESTING) {
|
||||||
return VERSION_4_ONLY_FOR_TESTING;
|
return VERSION_4_ONLY_FOR_TESTING;
|
||||||
} else if (ByteArrayUtils::readUint16(dict, 4) == VERSION_4) {
|
} else if (ByteArrayUtils::readUint16(dict, 4) == VERSION_4) {
|
||||||
|
|
|
@ -32,8 +32,9 @@ class FormatUtils {
|
||||||
// These MUST have the same values as the relevant constants in FormatSpec.java.
|
// These MUST have the same values as the relevant constants in FormatSpec.java.
|
||||||
VERSION_2 = 2,
|
VERSION_2 = 2,
|
||||||
VERSION_4_ONLY_FOR_TESTING = 399,
|
VERSION_4_ONLY_FOR_TESTING = 399,
|
||||||
VERSION_4 = 401,
|
VERSION_401 = 401,
|
||||||
VERSION_4_DEV = 402,
|
VERSION_4 = 402,
|
||||||
|
VERSION_4_DEV = 403,
|
||||||
UNKNOWN_VERSION = -1
|
UNKNOWN_VERSION = -1
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -64,7 +64,7 @@ public class BinaryDictionaryDecayingTests extends AndroidTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean supportsBeginningOfSentence(final int formatVersion) {
|
private static boolean supportsBeginningOfSentence(final int formatVersion) {
|
||||||
return formatVersion >= FormatSpec.VERSION4_DEV;
|
return formatVersion > FormatSpec.VERSION401;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addUnigramWord(final BinaryDictionary binaryDictionary, final String word,
|
private void addUnigramWord(final BinaryDictionary binaryDictionary, final String word,
|
||||||
|
|
|
@ -47,11 +47,11 @@ public class BinaryDictionaryTests extends AndroidTestCase {
|
||||||
new int[] { FormatSpec.VERSION4, FormatSpec.VERSION4_DEV };
|
new int[] { FormatSpec.VERSION4, FormatSpec.VERSION4_DEV };
|
||||||
|
|
||||||
private static boolean canCheckBigramProbability(final int formatVersion) {
|
private static boolean canCheckBigramProbability(final int formatVersion) {
|
||||||
return formatVersion >= FormatSpec.VERSION4_DEV;
|
return formatVersion > FormatSpec.VERSION401;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean supportsBeginningOfSentence(final int formatVersion) {
|
private static boolean supportsBeginningOfSentence(final int formatVersion) {
|
||||||
return formatVersion >= FormatSpec.VERSION4_DEV;
|
return formatVersion > FormatSpec.VERSION401;
|
||||||
}
|
}
|
||||||
|
|
||||||
private File createEmptyDictionaryAndGetFile(final String dictId,
|
private File createEmptyDictionaryAndGetFile(final String dictId,
|
||||||
|
|
Loading…
Reference in New Issue