Skip to content
Snippets Groups Projects
Commit c7387a4f authored by Jean Chalard's avatar Jean Chalard
Browse files

Add values for suggestion types (A120)

Also, use it in getBigrams.

Change-Id: Ia0be9b57d1b7effcd8a936e01e957d1195b39c68
parent 6931df9c
No related branches found
No related tags found
No related merge requests found
...@@ -125,6 +125,7 @@ public class SuggestedWords { ...@@ -125,6 +125,7 @@ public class SuggestedWords {
public static final int KIND_HARDCODED = 5; // Hardcoded suggestion, e.g. punctuation public static final int KIND_HARDCODED = 5; // Hardcoded suggestion, e.g. punctuation
public static final int KIND_APP_DEFINED = 6; // Suggested by the application public static final int KIND_APP_DEFINED = 6; // Suggested by the application
public static final int KIND_SHORTCUT = 7; // A shortcut public static final int KIND_SHORTCUT = 7; // A shortcut
public static final int KIND_PREDICTION = 8; // A prediction (== a suggestion with no input)
public final String mWord; public final String mWord;
public final int mScore; public final int mScore;
public final int mKind; // one of the KIND_* constants above public final int mKind; // one of the KIND_* constants above
......
...@@ -38,7 +38,7 @@ BigramDictionary::~BigramDictionary() { ...@@ -38,7 +38,7 @@ BigramDictionary::~BigramDictionary() {
} }
bool BigramDictionary::addWordBigram(unsigned short *word, int length, int frequency, bool BigramDictionary::addWordBigram(unsigned short *word, int length, int frequency,
int *bigramFreq, unsigned short *bigramChars) const { int *bigramFreq, unsigned short *bigramChars, int *outputTypes) const {
word[length] = 0; word[length] = 0;
if (DEBUG_DICT) { if (DEBUG_DICT) {
#ifdef FLAG_DBG #ifdef FLAG_DBG
...@@ -65,6 +65,7 @@ bool BigramDictionary::addWordBigram(unsigned short *word, int length, int frequ ...@@ -65,6 +65,7 @@ bool BigramDictionary::addWordBigram(unsigned short *word, int length, int frequ
(char*) bigramFreq + insertAt * sizeof(bigramFreq[0]), (char*) bigramFreq + insertAt * sizeof(bigramFreq[0]),
(MAX_PREDICTIONS - insertAt - 1) * sizeof(bigramFreq[0])); (MAX_PREDICTIONS - insertAt - 1) * sizeof(bigramFreq[0]));
bigramFreq[insertAt] = frequency; bigramFreq[insertAt] = frequency;
outputTypes[insertAt] = Dictionary::KIND_PREDICTION;
memmove((char*) bigramChars + (insertAt + 1) * MAX_WORD_LENGTH * sizeof(short), memmove((char*) bigramChars + (insertAt + 1) * MAX_WORD_LENGTH * sizeof(short),
(char*) bigramChars + (insertAt ) * MAX_WORD_LENGTH * sizeof(short), (char*) bigramChars + (insertAt ) * MAX_WORD_LENGTH * sizeof(short),
(MAX_PREDICTIONS - insertAt - 1) * sizeof(short) * MAX_WORD_LENGTH); (MAX_PREDICTIONS - insertAt - 1) * sizeof(short) * MAX_WORD_LENGTH);
...@@ -134,8 +135,8 @@ int BigramDictionary::getBigrams(const int32_t *prevWord, int prevWordLength, in ...@@ -134,8 +135,8 @@ int BigramDictionary::getBigrams(const int32_t *prevWord, int prevWordLength, in
// here, but it can't get too bad. // here, but it can't get too bad.
const int frequency = const int frequency =
BinaryFormat::computeFrequencyForBigram(unigramFreq, bigramFreqTemp); BinaryFormat::computeFrequencyForBigram(unigramFreq, bigramFreqTemp);
if (addWordBigram( if (addWordBigram(bigramBuffer, length, frequency, bigramFreq, bigramChars,
bigramBuffer, length, frequency, bigramFreq, bigramChars)) { outputTypes)) {
++bigramCount; ++bigramCount;
} }
} }
......
...@@ -39,7 +39,7 @@ class BigramDictionary { ...@@ -39,7 +39,7 @@ class BigramDictionary {
private: private:
DISALLOW_IMPLICIT_CONSTRUCTORS(BigramDictionary); DISALLOW_IMPLICIT_CONSTRUCTORS(BigramDictionary);
bool addWordBigram(unsigned short *word, int length, int frequency, bool addWordBigram(unsigned short *word, int length, int frequency,
int *bigramFreq, unsigned short *bigramChars) const; int *bigramFreq, unsigned short *bigramChars, int *outputTypes) const;
int getBigramAddress(int *pos, bool advance); int getBigramAddress(int *pos, bool advance);
int getBigramFreq(int *pos); int getBigramFreq(int *pos);
void searchForTerminalNode(int addressLookingFor, int frequency); void searchForTerminalNode(int addressLookingFor, int frequency);
......
...@@ -31,6 +31,17 @@ namespace latinime { ...@@ -31,6 +31,17 @@ namespace latinime {
class Dictionary { class Dictionary {
public: public:
// Taken from SuggestedWords.java
const static int KIND_TYPED = 0; // What user typed
const static int KIND_CORRECTION = 1; // Simple correction/suggestion
const static int KIND_COMPLETION = 2; // Completion (suggestion with appended chars)
const static int KIND_WHITELIST = 3; // Whitelisted word
const static int KIND_BLACKLIST = 4; // Blacklisted word
const static int KIND_HARDCODED = 5; // Hardcoded suggestion, e.g. punctuation
const static int KIND_APP_DEFINED = 6; // Suggested by the application
const static int KIND_SHORTCUT = 7; // A shortcut
const static int KIND_PREDICTION = 8; // A prediction (== a suggestion with no input)
Dictionary(void *dict, int dictSize, int mmapFd, int dictBufAdjust, int typedLetterMultipler, Dictionary(void *dict, int dictSize, int mmapFd, int dictBufAdjust, int typedLetterMultipler,
int fullWordMultiplier, int maxWordLength, int maxWords, int maxPredictions); int fullWordMultiplier, int maxWordLength, int maxWords, int maxPredictions);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment