am a88c9682: Merge "Change v403 historical info format."
* commit 'a88c9682fc97863d27b46932adc1218990e70bd7': Change v403 historical info format.main
commit
60826f008f
|
@ -38,6 +38,7 @@ class HistoricalInfo {
|
||||||
return mTimestamp;
|
return mTimestamp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Remove
|
||||||
int getLevel() const {
|
int getLevel() const {
|
||||||
return mLevel;
|
return mLevel;
|
||||||
}
|
}
|
||||||
|
|
|
@ -105,7 +105,7 @@ class ProbabilityEntry {
|
||||||
encodedEntry = (encodedEntry << (Ver4DictConstants::WORD_LEVEL_FIELD_SIZE * CHAR_BIT))
|
encodedEntry = (encodedEntry << (Ver4DictConstants::WORD_LEVEL_FIELD_SIZE * CHAR_BIT))
|
||||||
| static_cast<uint8_t>(mHistoricalInfo.getLevel());
|
| static_cast<uint8_t>(mHistoricalInfo.getLevel());
|
||||||
encodedEntry = (encodedEntry << (Ver4DictConstants::WORD_COUNT_FIELD_SIZE * CHAR_BIT))
|
encodedEntry = (encodedEntry << (Ver4DictConstants::WORD_COUNT_FIELD_SIZE * CHAR_BIT))
|
||||||
| static_cast<uint8_t>(mHistoricalInfo.getCount());
|
| static_cast<uint16_t>(mHistoricalInfo.getCount());
|
||||||
} else {
|
} else {
|
||||||
encodedEntry = (encodedEntry << (Ver4DictConstants::PROBABILITY_SIZE * CHAR_BIT))
|
encodedEntry = (encodedEntry << (Ver4DictConstants::PROBABILITY_SIZE * CHAR_BIT))
|
||||||
| static_cast<uint8_t>(mProbability);
|
| static_cast<uint8_t>(mProbability);
|
||||||
|
|
|
@ -49,8 +49,8 @@ const int Ver4DictConstants::TERMINAL_ADDRESS_TABLE_ADDRESS_SIZE = 3;
|
||||||
const int Ver4DictConstants::NOT_A_TERMINAL_ADDRESS = 0;
|
const int Ver4DictConstants::NOT_A_TERMINAL_ADDRESS = 0;
|
||||||
const int Ver4DictConstants::TERMINAL_ID_FIELD_SIZE = 4;
|
const int Ver4DictConstants::TERMINAL_ID_FIELD_SIZE = 4;
|
||||||
const int Ver4DictConstants::TIME_STAMP_FIELD_SIZE = 4;
|
const int Ver4DictConstants::TIME_STAMP_FIELD_SIZE = 4;
|
||||||
const int Ver4DictConstants::WORD_LEVEL_FIELD_SIZE = 1;
|
const int Ver4DictConstants::WORD_LEVEL_FIELD_SIZE = 0;
|
||||||
const int Ver4DictConstants::WORD_COUNT_FIELD_SIZE = 1;
|
const int Ver4DictConstants::WORD_COUNT_FIELD_SIZE = 2;
|
||||||
|
|
||||||
const uint8_t Ver4DictConstants::FLAG_REPRESENTS_BEGINNING_OF_SENTENCE = 0x1;
|
const uint8_t Ver4DictConstants::FLAG_REPRESENTS_BEGINNING_OF_SENTENCE = 0x1;
|
||||||
const uint8_t Ver4DictConstants::FLAG_NOT_A_VALID_ENTRY = 0x2;
|
const uint8_t Ver4DictConstants::FLAG_NOT_A_VALID_ENTRY = 0x2;
|
||||||
|
|
|
@ -47,6 +47,7 @@ class Ver4DictConstants {
|
||||||
static const int NOT_A_TERMINAL_ADDRESS;
|
static const int NOT_A_TERMINAL_ADDRESS;
|
||||||
static const int TERMINAL_ID_FIELD_SIZE;
|
static const int TERMINAL_ID_FIELD_SIZE;
|
||||||
static const int TIME_STAMP_FIELD_SIZE;
|
static const int TIME_STAMP_FIELD_SIZE;
|
||||||
|
// TODO: Remove
|
||||||
static const int WORD_LEVEL_FIELD_SIZE;
|
static const int WORD_LEVEL_FIELD_SIZE;
|
||||||
static const int WORD_COUNT_FIELD_SIZE;
|
static const int WORD_COUNT_FIELD_SIZE;
|
||||||
// Flags in probability entry.
|
// Flags in probability entry.
|
||||||
|
|
|
@ -52,16 +52,14 @@ TEST(LanguageModelDictContentTest, TestUnigramProbabilityWithHistoricalInfo) {
|
||||||
|
|
||||||
const int flag = 0xF0;
|
const int flag = 0xF0;
|
||||||
const int timestamp = 0x3FFFFFFF;
|
const int timestamp = 0x3FFFFFFF;
|
||||||
const int level = 3;
|
|
||||||
const int count = 10;
|
const int count = 10;
|
||||||
const int wordId = 100;
|
const int wordId = 100;
|
||||||
const HistoricalInfo historicalInfo(timestamp, level, count);
|
const HistoricalInfo historicalInfo(timestamp, 0 /* level */, count);
|
||||||
const ProbabilityEntry probabilityEntry(flag, &historicalInfo);
|
const ProbabilityEntry probabilityEntry(flag, &historicalInfo);
|
||||||
languageModelDictContent.setProbabilityEntry(wordId, &probabilityEntry);
|
languageModelDictContent.setProbabilityEntry(wordId, &probabilityEntry);
|
||||||
const ProbabilityEntry entry = languageModelDictContent.getProbabilityEntry(wordId);
|
const ProbabilityEntry entry = languageModelDictContent.getProbabilityEntry(wordId);
|
||||||
EXPECT_EQ(flag, entry.getFlags());
|
EXPECT_EQ(flag, entry.getFlags());
|
||||||
EXPECT_EQ(timestamp, entry.getHistoricalInfo()->getTimestamp());
|
EXPECT_EQ(timestamp, entry.getHistoricalInfo()->getTimestamp());
|
||||||
EXPECT_EQ(level, entry.getHistoricalInfo()->getLevel());
|
|
||||||
EXPECT_EQ(count, entry.getHistoricalInfo()->getCount());
|
EXPECT_EQ(count, entry.getHistoricalInfo()->getCount());
|
||||||
|
|
||||||
// Remove
|
// Remove
|
||||||
|
|
|
@ -39,20 +39,18 @@ TEST(ProbabilityEntryTest, TestEncodeDecode) {
|
||||||
TEST(ProbabilityEntryTest, TestEncodeDecodeWithHistoricalInfo) {
|
TEST(ProbabilityEntryTest, TestEncodeDecodeWithHistoricalInfo) {
|
||||||
const int flag = 0xF0;
|
const int flag = 0xF0;
|
||||||
const int timestamp = 0x3FFFFFFF;
|
const int timestamp = 0x3FFFFFFF;
|
||||||
const int level = 3;
|
const int count = 0xABCD;
|
||||||
const int count = 10;
|
|
||||||
|
|
||||||
const HistoricalInfo historicalInfo(timestamp, level, count);
|
const HistoricalInfo historicalInfo(timestamp, 0 /* level */, count);
|
||||||
const ProbabilityEntry entry(flag, &historicalInfo);
|
const ProbabilityEntry entry(flag, &historicalInfo);
|
||||||
|
|
||||||
const uint64_t encodedEntry = entry.encode(true /* hasHistoricalInfo */);
|
const uint64_t encodedEntry = entry.encode(true /* hasHistoricalInfo */);
|
||||||
EXPECT_EQ(0xF03FFFFFFF030Aull, encodedEntry);
|
EXPECT_EQ(0xF03FFFFFFFABCDull, encodedEntry);
|
||||||
const ProbabilityEntry decodedEntry =
|
const ProbabilityEntry decodedEntry =
|
||||||
ProbabilityEntry::decode(encodedEntry, true /* hasHistoricalInfo */);
|
ProbabilityEntry::decode(encodedEntry, true /* hasHistoricalInfo */);
|
||||||
|
|
||||||
EXPECT_EQ(flag, decodedEntry.getFlags());
|
EXPECT_EQ(flag, decodedEntry.getFlags());
|
||||||
EXPECT_EQ(timestamp, decodedEntry.getHistoricalInfo()->getTimestamp());
|
EXPECT_EQ(timestamp, decodedEntry.getHistoricalInfo()->getTimestamp());
|
||||||
EXPECT_EQ(level, decodedEntry.getHistoricalInfo()->getLevel());
|
|
||||||
EXPECT_EQ(count, decodedEntry.getHistoricalInfo()->getCount());
|
EXPECT_EQ(count, decodedEntry.getHistoricalInfo()->getCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue