Merge "Get n-gram probability in structure policy." into lmp-dev
commit
2e32e83b6e
|
@ -88,13 +88,7 @@ void Dictionary::getPredictions(const PrevWordsInfo *const prevWordsInfo,
|
||||||
}
|
}
|
||||||
|
|
||||||
int Dictionary::getProbability(const int *word, int length) const {
|
int Dictionary::getProbability(const int *word, int length) const {
|
||||||
TimeKeeper::setCurrentTime();
|
return getNgramProbability(nullptr /* prevWordsInfo */, word, length);
|
||||||
int pos = getDictionaryStructurePolicy()->getTerminalPtNodePositionOfWord(word, length,
|
|
||||||
false /* forceLowerCaseSearch */);
|
|
||||||
if (NOT_A_DICT_POS == pos) {
|
|
||||||
return NOT_A_PROBABILITY;
|
|
||||||
}
|
|
||||||
return getDictionaryStructurePolicy()->getProbabilityOfPtNode(nullptr /* prevWordsInfo */, pos);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int Dictionary::getMaxProbabilityOfExactMatches(const int *word, int length) const {
|
int Dictionary::getMaxProbabilityOfExactMatches(const int *word, int length) const {
|
||||||
|
@ -109,18 +103,7 @@ int Dictionary::getNgramProbability(const PrevWordsInfo *const prevWordsInfo, co
|
||||||
int nextWordPos = mDictionaryStructureWithBufferPolicy->getTerminalPtNodePositionOfWord(word,
|
int nextWordPos = mDictionaryStructureWithBufferPolicy->getTerminalPtNodePositionOfWord(word,
|
||||||
length, false /* forceLowerCaseSearch */);
|
length, false /* forceLowerCaseSearch */);
|
||||||
if (NOT_A_DICT_POS == nextWordPos) return NOT_A_PROBABILITY;
|
if (NOT_A_DICT_POS == nextWordPos) return NOT_A_PROBABILITY;
|
||||||
BinaryDictionaryBigramsIterator bigramsIt = prevWordsInfo->getBigramsIteratorForPrediction(
|
return getDictionaryStructurePolicy()->getProbabilityOfPtNode(prevWordsInfo, nextWordPos);
|
||||||
mDictionaryStructureWithBufferPolicy.get());
|
|
||||||
while (bigramsIt.hasNext()) {
|
|
||||||
bigramsIt.next();
|
|
||||||
if (bigramsIt.getBigramPos() == nextWordPos
|
|
||||||
&& bigramsIt.getProbability() != NOT_A_PROBABILITY) {
|
|
||||||
return mDictionaryStructureWithBufferPolicy->getProbability(
|
|
||||||
mDictionaryStructureWithBufferPolicy->getProbabilityOfPtNode(
|
|
||||||
nullptr /* prevWordsInfo */, nextWordPos), bigramsIt.getProbability());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return NOT_A_PROBABILITY;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Dictionary::addUnigramEntry(const int *const word, const int length,
|
bool Dictionary::addUnigramEntry(const int *const word, const int length,
|
||||||
|
|
|
@ -140,6 +140,18 @@ int Ver4PatriciaTriePolicy::getProbabilityOfPtNode(const PrevWordsInfo *const pr
|
||||||
if (ptNodeParams.isDeleted() || ptNodeParams.isBlacklisted() || ptNodeParams.isNotAWord()) {
|
if (ptNodeParams.isDeleted() || ptNodeParams.isBlacklisted() || ptNodeParams.isNotAWord()) {
|
||||||
return NOT_A_PROBABILITY;
|
return NOT_A_PROBABILITY;
|
||||||
}
|
}
|
||||||
|
if (prevWordsInfo) {
|
||||||
|
BinaryDictionaryBigramsIterator bigramsIt =
|
||||||
|
prevWordsInfo->getBigramsIteratorForPrediction(this /* dictStructurePolicy */);
|
||||||
|
while (bigramsIt.hasNext()) {
|
||||||
|
bigramsIt.next();
|
||||||
|
if (bigramsIt.getBigramPos() == ptNodePos
|
||||||
|
&& bigramsIt.getProbability() != NOT_A_PROBABILITY) {
|
||||||
|
return getProbability(ptNodeParams.getProbability(), bigramsIt.getProbability());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return NOT_A_PROBABILITY;
|
||||||
|
}
|
||||||
return getProbability(ptNodeParams.getProbability(), NOT_A_PROBABILITY);
|
return getProbability(ptNodeParams.getProbability(), NOT_A_PROBABILITY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
#include "suggest/core/dicnode/dic_node.h"
|
#include "suggest/core/dicnode/dic_node.h"
|
||||||
#include "suggest/core/dicnode/dic_node_vector.h"
|
#include "suggest/core/dicnode/dic_node_vector.h"
|
||||||
#include "suggest/core/dictionary/binary_dictionary_bigrams_iterator.h"
|
#include "suggest/core/dictionary/binary_dictionary_bigrams_iterator.h"
|
||||||
|
#include "suggest/core/session/prev_words_info.h"
|
||||||
#include "suggest/policyimpl/dictionary/structure/pt_common/dynamic_pt_reading_helper.h"
|
#include "suggest/policyimpl/dictionary/structure/pt_common/dynamic_pt_reading_helper.h"
|
||||||
#include "suggest/policyimpl/dictionary/structure/pt_common/patricia_trie_reading_utils.h"
|
#include "suggest/policyimpl/dictionary/structure/pt_common/patricia_trie_reading_utils.h"
|
||||||
#include "suggest/policyimpl/dictionary/utils/probability_utils.h"
|
#include "suggest/policyimpl/dictionary/utils/probability_utils.h"
|
||||||
|
@ -297,10 +298,6 @@ int PatriciaTriePolicy::getProbability(const int unigramProbability,
|
||||||
|
|
||||||
int PatriciaTriePolicy::getProbabilityOfPtNode(const PrevWordsInfo *const prevWordsInfo,
|
int PatriciaTriePolicy::getProbabilityOfPtNode(const PrevWordsInfo *const prevWordsInfo,
|
||||||
const int ptNodePos) const {
|
const int ptNodePos) const {
|
||||||
if (prevWordsInfo) {
|
|
||||||
// TODO: Return probability using prevWordsInfo.
|
|
||||||
return NOT_A_PROBABILITY;
|
|
||||||
}
|
|
||||||
if (ptNodePos == NOT_A_DICT_POS) {
|
if (ptNodePos == NOT_A_DICT_POS) {
|
||||||
return NOT_A_PROBABILITY;
|
return NOT_A_PROBABILITY;
|
||||||
}
|
}
|
||||||
|
@ -312,6 +309,18 @@ int PatriciaTriePolicy::getProbabilityOfPtNode(const PrevWordsInfo *const prevWo
|
||||||
// for shortcuts).
|
// for shortcuts).
|
||||||
return NOT_A_PROBABILITY;
|
return NOT_A_PROBABILITY;
|
||||||
}
|
}
|
||||||
|
if (prevWordsInfo) {
|
||||||
|
BinaryDictionaryBigramsIterator bigramsIt =
|
||||||
|
prevWordsInfo->getBigramsIteratorForPrediction(this /* dictStructurePolicy */);
|
||||||
|
while (bigramsIt.hasNext()) {
|
||||||
|
bigramsIt.next();
|
||||||
|
if (bigramsIt.getBigramPos() == ptNodePos
|
||||||
|
&& bigramsIt.getProbability() != NOT_A_PROBABILITY) {
|
||||||
|
return getProbability(ptNodeParams.getProbability(), bigramsIt.getProbability());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return NOT_A_PROBABILITY;
|
||||||
|
}
|
||||||
return getProbability(ptNodeParams.getProbability(), NOT_A_PROBABILITY);
|
return getProbability(ptNodeParams.getProbability(), NOT_A_PROBABILITY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -123,10 +123,6 @@ int Ver4PatriciaTriePolicy::getProbability(const int unigramProbability,
|
||||||
|
|
||||||
int Ver4PatriciaTriePolicy::getProbabilityOfPtNode(const PrevWordsInfo *const prevWordsInfo,
|
int Ver4PatriciaTriePolicy::getProbabilityOfPtNode(const PrevWordsInfo *const prevWordsInfo,
|
||||||
const int ptNodePos) const {
|
const int ptNodePos) const {
|
||||||
if (prevWordsInfo) {
|
|
||||||
// TODO: Return probability using prevWordsInfo.
|
|
||||||
return NOT_A_PROBABILITY;
|
|
||||||
}
|
|
||||||
if (ptNodePos == NOT_A_DICT_POS) {
|
if (ptNodePos == NOT_A_DICT_POS) {
|
||||||
return NOT_A_PROBABILITY;
|
return NOT_A_PROBABILITY;
|
||||||
}
|
}
|
||||||
|
@ -134,6 +130,18 @@ int Ver4PatriciaTriePolicy::getProbabilityOfPtNode(const PrevWordsInfo *const pr
|
||||||
if (ptNodeParams.isDeleted() || ptNodeParams.isBlacklisted() || ptNodeParams.isNotAWord()) {
|
if (ptNodeParams.isDeleted() || ptNodeParams.isBlacklisted() || ptNodeParams.isNotAWord()) {
|
||||||
return NOT_A_PROBABILITY;
|
return NOT_A_PROBABILITY;
|
||||||
}
|
}
|
||||||
|
if (prevWordsInfo) {
|
||||||
|
BinaryDictionaryBigramsIterator bigramsIt =
|
||||||
|
prevWordsInfo->getBigramsIteratorForPrediction(this /* dictStructurePolicy */);
|
||||||
|
while (bigramsIt.hasNext()) {
|
||||||
|
bigramsIt.next();
|
||||||
|
if (bigramsIt.getBigramPos() == ptNodePos
|
||||||
|
&& bigramsIt.getProbability() != NOT_A_PROBABILITY) {
|
||||||
|
return getProbability(ptNodeParams.getProbability(), bigramsIt.getProbability());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return NOT_A_PROBABILITY;
|
||||||
|
}
|
||||||
return getProbability(ptNodeParams.getProbability(), NOT_A_PROBABILITY);
|
return getProbability(ptNodeParams.getProbability(), NOT_A_PROBABILITY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue