am 3bd64441: Merge "Implement TerminalPositionLookupTable."
* commit '3bd64441a6e6adae613fc57c6a545cd3cf48d043': Implement TerminalPositionLookupTable.main
commit
48e2c95d7a
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef LATINIME_TERMINAL_POSITION_LOOKUP_TABLE_H
|
||||
#define LATINIME_TERMINAL_POSITION_LOOKUP_TABLE_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "defines.h"
|
||||
#include "suggest/policyimpl/dictionary/structure/v4/content/single_dict_content.h"
|
||||
#include "suggest/policyimpl/dictionary/structure/v4/ver4_dict_constants.h"
|
||||
#include "suggest/policyimpl/dictionary/structure/v4/ver4_patricia_trie_reading_utils.h"
|
||||
#include "suggest/policyimpl/dictionary/utils/buffer_with_extendable_buffer.h"
|
||||
|
||||
namespace latinime {
|
||||
|
||||
class TerminalPositionLookupTable : public SingleDictContent {
|
||||
public:
|
||||
TerminalPositionLookupTable(const char *const dictDirPath, const bool isUpdatable)
|
||||
: SingleDictContent(dictDirPath,
|
||||
Ver4DictConstants::TERMINAL_ADDRESS_TABLE_FILE_EXTENSION, isUpdatable),
|
||||
mSize(getBuffer()->getTailPosition()
|
||||
/ Ver4DictConstants::TERMINAL_ADDRESS_TABLE_ADDRESS_SIZE) {}
|
||||
|
||||
int getTerminalPtNodePosition(const int terminalId) const {
|
||||
if (terminalId < 0 || terminalId >= mSize) {
|
||||
return NOT_A_DICT_POS;
|
||||
}
|
||||
const int readingPos = terminalId * Ver4DictConstants::TERMINAL_ADDRESS_TABLE_ADDRESS_SIZE;
|
||||
return getBuffer()->readUint(Ver4DictConstants::TERMINAL_ADDRESS_TABLE_ADDRESS_SIZE,
|
||||
readingPos);
|
||||
}
|
||||
|
||||
private:
|
||||
DISALLOW_IMPLICIT_CONSTRUCTORS(TerminalPositionLookupTable);
|
||||
|
||||
const int mSize;
|
||||
};
|
||||
} // namespace latinime
|
||||
#endif // LATINIME_TERMINAL_POSITION_LOOKUP_TABLE_H
|
|
@ -21,6 +21,7 @@
|
|||
#include "suggest/policyimpl/dictionary/structure/v4/content/probability_dict_content.h"
|
||||
#include "suggest/policyimpl/dictionary/structure/v4/content/single_dict_content.h"
|
||||
#include "suggest/policyimpl/dictionary/structure/v4/content/sparse_table_dict_content.h"
|
||||
#include "suggest/policyimpl/dictionary/structure/v4/content/terminal_position_lookup_table.h"
|
||||
#include "suggest/policyimpl/dictionary/structure/v4/ver4_dict_constants.h"
|
||||
#include "suggest/policyimpl/dictionary/utils/buffer_with_extendable_buffer.h"
|
||||
#include "suggest/policyimpl/dictionary/utils/mmapped_buffer.h"
|
||||
|
@ -39,7 +40,7 @@ class Ver4DictBuffers {
|
|||
|
||||
AK_FORCE_INLINE bool isValid() const {
|
||||
return mDictBuffer.get() != 0 && mProbabilityDictContent.isValid()
|
||||
&& mTerminalAddressTable.isValid() && mBigramDictContent.isValid()
|
||||
&& mTerminalPositionLookupTable.isValid() && mBigramDictContent.isValid()
|
||||
&& mShortcutDictContent.isValid();
|
||||
}
|
||||
|
||||
|
@ -61,8 +62,7 @@ class Ver4DictBuffers {
|
|||
AK_FORCE_INLINE Ver4DictBuffers(const char *const dictDirPath,
|
||||
const MmappedBuffer::MmappedBufferPtr &dictBuffer, const bool isUpdatable)
|
||||
: mDictBuffer(dictBuffer),
|
||||
mTerminalAddressTable(dictDirPath,
|
||||
Ver4DictConstants::TERMINAL_ADDRESS_TABLE_FILE_EXTENSION, isUpdatable),
|
||||
mTerminalPositionLookupTable(dictDirPath, isUpdatable),
|
||||
mProbabilityDictContent(dictDirPath, isUpdatable),
|
||||
mBigramDictContent(dictDirPath,
|
||||
Ver4DictConstants::BIGRAM_LOOKUP_TABLE_FILE_EXTENSION,
|
||||
|
@ -78,7 +78,7 @@ class Ver4DictBuffers {
|
|||
Ver4DictConstants::SHORTCUT_ADDRESS_TABLE_DATA_SIZE) {}
|
||||
|
||||
const MmappedBuffer::MmappedBufferPtr mDictBuffer;
|
||||
SingleDictContent mTerminalAddressTable;
|
||||
TerminalPositionLookupTable mTerminalPositionLookupTable;
|
||||
ProbabilityDictContent mProbabilityDictContent;
|
||||
SparseTableDictContent mBigramDictContent;
|
||||
SparseTableDictContent mShortcutDictContent;
|
||||
|
|
|
@ -33,6 +33,7 @@ const char *const Ver4DictConstants::SHORTCUT_CONTENT_TABLE_FILE_EXTENSION =
|
|||
const int Ver4DictConstants::NOT_A_TERMINAL_ID = -1;
|
||||
const int Ver4DictConstants::PROBABILITY_SIZE = 1;
|
||||
const int Ver4DictConstants::FLAGS_IN_PROBABILITY_FILE_SIZE = 1;
|
||||
const int Ver4DictConstants::TERMINAL_ADDRESS_TABLE_ADDRESS_SIZE = 3;
|
||||
|
||||
const int Ver4DictConstants::BIGRAM_ADDRESS_TABLE_BLOCK_SIZE = 4;
|
||||
const int Ver4DictConstants::BIGRAM_ADDRESS_TABLE_DATA_SIZE = 4;
|
||||
|
|
|
@ -37,6 +37,7 @@ class Ver4DictConstants {
|
|||
static const int NOT_A_TERMINAL_ID;
|
||||
static const int PROBABILITY_SIZE;
|
||||
static const int FLAGS_IN_PROBABILITY_FILE_SIZE;
|
||||
static const int TERMINAL_ADDRESS_TABLE_ADDRESS_SIZE;
|
||||
|
||||
static const int BIGRAM_ADDRESS_TABLE_BLOCK_SIZE;
|
||||
static const int BIGRAM_ADDRESS_TABLE_DATA_SIZE;
|
||||
|
|
|
@ -29,10 +29,10 @@ namespace latinime {
|
|||
|
||||
/* static */ int Ver4PatriciaTrieReadingUtils::getProbability(
|
||||
const BufferWithExtendableBuffer *const probabilityBuffer, const int terminalId) {
|
||||
int pos = terminalId * (Ver4DictConstants::FLAGS_IN_PROBABILITY_FILE_SIZE
|
||||
const int pos = terminalId * (Ver4DictConstants::FLAGS_IN_PROBABILITY_FILE_SIZE
|
||||
+ Ver4DictConstants::PROBABILITY_SIZE)
|
||||
+ Ver4DictConstants::FLAGS_IN_PROBABILITY_FILE_SIZE;
|
||||
return probabilityBuffer->readUintAndAdvancePosition(Ver4DictConstants::PROBABILITY_SIZE, &pos);
|
||||
return probabilityBuffer->readUint(Ver4DictConstants::PROBABILITY_SIZE, pos);
|
||||
}
|
||||
|
||||
} // namespace latinime
|
||||
|
|
Loading…
Reference in New Issue