2009-03-13 22:11:42 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2009 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_DICTIONARY_H
|
|
|
|
#define LATINIME_DICTIONARY_H
|
|
|
|
|
2012-08-02 10:48:08 +00:00
|
|
|
#include <stdint.h>
|
2012-05-02 07:00:24 +00:00
|
|
|
|
2010-12-02 05:53:24 +00:00
|
|
|
#include "defines.h"
|
2010-12-01 12:22:15 +00:00
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
namespace latinime {
|
|
|
|
|
2012-08-02 10:48:08 +00:00
|
|
|
class BigramDictionary;
|
|
|
|
class IncrementalDecoderInterface;
|
|
|
|
class ProximityInfo;
|
|
|
|
class UnigramDictionary;
|
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
class Dictionary {
|
2012-01-06 03:24:38 +00:00
|
|
|
public:
|
2012-07-12 06:21:11 +00:00
|
|
|
// 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)
|
|
|
|
|
2012-10-08 02:46:14 +00:00
|
|
|
Dictionary(void *dict, int dictSize, int mmapFd, int dictBufAdjust, int fullWordMultiplier,
|
|
|
|
int maxWordLength, int maxWords, int maxPredictions);
|
2011-12-14 06:04:58 +00:00
|
|
|
|
2012-08-08 12:23:25 +00:00
|
|
|
int getSuggestions(ProximityInfo *proximityInfo, void *traverseSession, int *xcoordinates,
|
|
|
|
int *ycoordinates, int *times, int *pointerIds, int *codes, int codesSize,
|
|
|
|
int *prevWordChars, int prevWordLength, int commitPoint, bool isGesture,
|
2012-06-25 08:44:54 +00:00
|
|
|
bool useFullEditDistance, unsigned short *outWords,
|
2012-08-15 07:57:32 +00:00
|
|
|
int *frequencies, int *spaceIndices, int *outputTypes) const;
|
2010-12-01 12:22:15 +00:00
|
|
|
|
2012-04-23 06:37:07 +00:00
|
|
|
int getBigrams(const int32_t *word, int length, int *codes, int codesSize,
|
2012-08-02 10:48:08 +00:00
|
|
|
unsigned short *outWords, int *frequencies, int *outputTypes) const;
|
2011-02-22 08:28:55 +00:00
|
|
|
|
2012-06-14 23:35:23 +00:00
|
|
|
int getFrequency(const int32_t *word, int length) const;
|
|
|
|
bool isValidBigram(const int32_t *word1, int length1, const int32_t *word2, int length2) const;
|
2012-08-14 05:22:27 +00:00
|
|
|
const uint8_t *getDict() const { // required to release dictionary buffer
|
|
|
|
return mDict;
|
2012-08-12 02:10:48 +00:00
|
|
|
}
|
2012-08-14 05:22:27 +00:00
|
|
|
const uint8_t *getOffsetDict() const {
|
|
|
|
return mOffsetDict;
|
2012-08-12 02:10:48 +00:00
|
|
|
}
|
2012-06-14 23:35:23 +00:00
|
|
|
int getDictSize() const { return mDictSize; }
|
|
|
|
int getMmapFd() const { return mMmapFd; }
|
|
|
|
int getDictBufAdjust() const { return mDictBufAdjust; }
|
2012-08-02 10:48:08 +00:00
|
|
|
virtual ~Dictionary();
|
2009-03-31 17:51:17 +00:00
|
|
|
|
2010-12-02 05:53:24 +00:00
|
|
|
// public static utility methods
|
|
|
|
// static inline methods should be defined in the header file
|
2010-12-02 09:11:54 +00:00
|
|
|
static int wideStrLen(unsigned short *str);
|
2011-06-17 03:45:17 +00:00
|
|
|
|
2012-01-06 03:24:38 +00:00
|
|
|
private:
|
2012-06-14 18:25:50 +00:00
|
|
|
DISALLOW_IMPLICIT_CONSTRUCTORS(Dictionary);
|
2012-08-14 05:22:27 +00:00
|
|
|
const uint8_t *mDict;
|
|
|
|
const uint8_t *mOffsetDict;
|
2011-01-07 06:01:51 +00:00
|
|
|
|
|
|
|
// Used only for the mmap version of dictionary loading, but we use these as dummy variables
|
|
|
|
// also for the malloc version.
|
|
|
|
const int mDictSize;
|
|
|
|
const int mMmapFd;
|
|
|
|
const int mDictBufAdjust;
|
|
|
|
|
2012-06-14 18:25:50 +00:00
|
|
|
const UnigramDictionary *mUnigramDictionary;
|
2012-06-14 23:35:23 +00:00
|
|
|
const BigramDictionary *mBigramDictionary;
|
2012-06-29 23:53:33 +00:00
|
|
|
IncrementalDecoderInterface *mGestureDecoder;
|
2009-03-13 22:11:42 +00:00
|
|
|
};
|
|
|
|
|
2010-12-02 05:53:24 +00:00
|
|
|
// public static utility methods
|
|
|
|
// static inline methods should be defined in the header file
|
2010-12-02 09:11:54 +00:00
|
|
|
inline int Dictionary::wideStrLen(unsigned short *str) {
|
|
|
|
if (!str) return 0;
|
2012-09-04 03:49:46 +00:00
|
|
|
int length = 0;
|
|
|
|
while (*str) {
|
|
|
|
str++;
|
|
|
|
length++;
|
2012-08-12 02:10:48 +00:00
|
|
|
}
|
2012-09-04 03:49:46 +00:00
|
|
|
return length;
|
2010-12-02 09:11:54 +00:00
|
|
|
}
|
2011-06-18 04:09:55 +00:00
|
|
|
} // namespace latinime
|
2009-03-13 22:11:42 +00:00
|
|
|
#endif // LATINIME_DICTIONARY_H
|