aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--java/res/values/strings.xml18
-rw-r--r--java/src/com/android/inputmethod/latin/LatinIME.java1
-rw-r--r--java/src/com/android/inputmethod/latin/spellcheck/AndroidWordLevelSpellCheckerSession.java2
-rw-r--r--java/src/com/android/inputmethod/research/ResearchLogger.java3
-rw-r--r--native/jni/Android.mk36
-rw-r--r--native/jni/jni_common.cpp4
-rw-r--r--native/jni/src/bigram_dictionary.cpp6
-rw-r--r--native/jni/src/correction.cpp20
-rw-r--r--native/jni/src/correction.h2
-rw-r--r--native/jni/src/defines.h1
-rw-r--r--native/jni/src/dictionary.cpp40
-rw-r--r--native/jni/src/dictionary.h1
-rw-r--r--native/jni/src/digraph_utils.cpp93
-rw-r--r--native/jni/src/digraph_utils.h47
-rw-r--r--native/jni/src/suggest/core/dictionary/shortcut_utils.h2
-rw-r--r--native/jni/src/suggest/core/policy/traversal.h3
-rw-r--r--native/jni/src/suggest/core/policy/weighting.cpp11
-rw-r--r--native/jni/src/suggest/core/policy/weighting.h1
-rw-r--r--native/jni/src/suggest/core/session/dic_traverse_session.cpp5
-rw-r--r--native/jni/src/suggest/core/session/dic_traverse_session.h2
-rw-r--r--native/jni/src/suggest/core/suggest.cpp18
-rw-r--r--native/jni/src/suggest/core/suggest.h4
-rw-r--r--native/jni/src/suggest/core/suggest_interface.h (renamed from native/jni/src/suggest/suggest_interface.h)0
-rw-r--r--native/jni/src/suggest/gesture_suggest.h61
-rw-r--r--native/jni/src/suggest/policyimpl/gesture/gesture_suggest_policy_factory.cpp (renamed from native/jni/src/suggest/typing_suggest.cpp)8
-rw-r--r--native/jni/src/suggest/policyimpl/gesture/gesture_suggest_policy_factory.h44
-rw-r--r--native/jni/src/suggest/policyimpl/typing/scoring_params.cpp2
-rw-r--r--native/jni/src/suggest/policyimpl/typing/typing_scoring.cpp2
-rw-r--r--native/jni/src/suggest/policyimpl/typing/typing_scoring.h4
-rw-r--r--native/jni/src/suggest/policyimpl/typing/typing_suggest_policy.cpp23
-rw-r--r--native/jni/src/suggest/policyimpl/typing/typing_suggest_policy.h8
-rw-r--r--native/jni/src/suggest/policyimpl/typing/typing_suggest_policy_factory.h (renamed from native/jni/src/suggest/gesture_suggest.cpp)22
-rw-r--r--native/jni/src/suggest/policyimpl/typing/typing_traversal.cpp2
-rw-r--r--native/jni/src/suggest/policyimpl/typing/typing_traversal.h10
-rw-r--r--native/jni/src/suggest/policyimpl/typing/typing_weighting.cpp7
-rw-r--r--native/jni/src/suggest/policyimpl/typing/typing_weighting.h7
-rw-r--r--native/jni/src/suggest/typing_suggest.h61
-rw-r--r--native/jni/src/unigram_dictionary.cpp31
-rw-r--r--native/jni/src/unigram_dictionary.h10
39 files changed, 343 insertions, 279 deletions
diff --git a/java/res/values/strings.xml b/java/res/values/strings.xml
index ebcd3d956..201fc7030 100644
--- a/java/res/values/strings.xml
+++ b/java/res/values/strings.xml
@@ -350,10 +350,10 @@
<!-- Inform the user that a particular language has an available dictionary -->
<string name="has_dictionary">Dictionary available</string>
- <!-- Preferences item for enabling to send user statistics to Google -->
+ <!-- Preferences item for enabling to send user statistics for development only diagnostics -->
<string name="prefs_enable_log">Enable user feedback</string>
- <!-- Description for enabling to send user statistics to Google -->
- <string name="prefs_description_log">Help improve this input method editor by automatically sending usage statistics and crash reports to Google.</string>
+ <!-- Description for enabling to send user statistics for development only diagnostics -->
+ <string name="prefs_description_log">Help improve this input method editor by automatically sending usage statistics and crash reports</string>
<!-- Title of the item to change the keyboard theme [CHAR LIMIT=20]-->
<string name="keyboard_layout">Keyboard theme</string>
@@ -422,12 +422,12 @@
<!-- Title of an option for usability study mode -->
<string name="prefs_usability_study_mode">Usability study mode</string>
- <!-- Title of the settings for key long press delay -->
- <string name="prefs_key_longpress_timeout_settings">Key long press delay settings</string>
- <!-- Title of the settings for keypress vibration duration -->
- <string name="prefs_keypress_vibration_duration_settings">Keypress vibration duration settings</string>
- <!-- Title of the settings for keypress sound volume -->
- <string name="prefs_keypress_sound_volume_settings">Keypress sound volume settings</string>
+ <!-- Title of the settings for key long press delay [CHAR LIMIT=30] -->
+ <string name="prefs_key_longpress_timeout_settings">Key long press delay</string>
+ <!-- Title of the settings for keypress vibration duration [CHAR LIMIT=30] -->
+ <string name="prefs_keypress_vibration_duration_settings">Keypress vibration duration</string>
+ <!-- Title of the settings for keypress sound volume [CHAR LIMIT=30] -->
+ <string name="prefs_keypress_sound_volume_settings">Keypress sound volume</string>
<!-- Title of the settings for reading an external dictionary file -->
<string name="prefs_read_external_dictionary">Read external dictionary file</string>
<!-- Message to show when there are no files to install as an external dictionary [CHAR LIMIT=100] -->
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index 0fc26a80e..3262a9a10 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -1905,7 +1905,6 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
private boolean handleSeparator(final int primaryCode, final int x, final int y,
final int spaceState) {
if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) {
- ResearchLogger.recordTimeForLogUnitSplit();
ResearchLogger.latinIME_handleSeparator(primaryCode, mWordComposer.isComposingWord());
}
boolean didAutoCorrect = false;
diff --git a/java/src/com/android/inputmethod/latin/spellcheck/AndroidWordLevelSpellCheckerSession.java b/java/src/com/android/inputmethod/latin/spellcheck/AndroidWordLevelSpellCheckerSession.java
index 96cd3ecfd..b15063235 100644
--- a/java/src/com/android/inputmethod/latin/spellcheck/AndroidWordLevelSpellCheckerSession.java
+++ b/java/src/com/android/inputmethod/latin/spellcheck/AndroidWordLevelSpellCheckerSession.java
@@ -150,7 +150,7 @@ public abstract class AndroidWordLevelSpellCheckerSession extends Session {
// Greek letters are either in the 370~3FF range (Greek & Coptic), or in the
// 1F00~1FFF range (Greek extended). Our dictionary contains both sort of characters.
// Our dictionary also contains a few words with 0xF2; it would be best to check
- // if that's correct, but a Google search does return results for these words so
+ // if that's correct, but a web search does return results for these words so
// they are probably okay.
return (codePoint >= 0x370 && codePoint <= 0x3FF)
|| (codePoint >= 0x1F00 && codePoint <= 0x1FFF)
diff --git a/java/src/com/android/inputmethod/research/ResearchLogger.java b/java/src/com/android/inputmethod/research/ResearchLogger.java
index fbfa9c977..fa124f3ba 100644
--- a/java/src/com/android/inputmethod/research/ResearchLogger.java
+++ b/java/src/com/android/inputmethod/research/ResearchLogger.java
@@ -790,8 +790,7 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang
}
private boolean isAllowedToLog() {
- return !mIsPasswordView && !mIsLoggingSuspended && sIsLogging && !mInFeedbackDialog
- && !isReplaying();
+ return !mIsPasswordView && !mIsLoggingSuspended && sIsLogging && !mInFeedbackDialog;
}
public void requestIndicatorRedraw() {
diff --git a/native/jni/Android.mk b/native/jni/Android.mk
index b476fc3d1..cbe9515fe 100644
--- a/native/jni/Android.mk
+++ b/native/jni/Android.mk
@@ -24,20 +24,14 @@ FLAG_DO_PROFILE ?= false
include $(CLEAR_VARS)
LATIN_IME_SRC_DIR := src
-LATIN_IME_SRC_FULLPATH_DIR := $(LOCAL_PATH)/$(LATIN_IME_SRC_DIR)
-LOCAL_C_INCLUDES += \
- $(LATIN_IME_SRC_FULLPATH_DIR) \
- $(LATIN_IME_SRC_FULLPATH_DIR)/suggest \
- $(LATIN_IME_SRC_FULLPATH_DIR)/suggest/core \
- $(addprefix $(LATIN_IME_SRC_FULLPATH_DIR)/suggest/core/, dicnode dictionary policy session) \
- $(LATIN_IME_SRC_FULLPATH_DIR)/suggest/policyimpl/typing
+LOCAL_C_INCLUDES += $(LOCAL_PATH)/$(LATIN_IME_SRC_DIR)
LOCAL_CFLAGS += -Werror -Wall -Wextra -Weffc++ -Wformat=2 -Wcast-qual -Wcast-align \
-Wwrite-strings -Wfloat-equal -Wpointer-arith -Winit-self -Wredundant-decls -Wno-system-headers
ifeq ($(TARGET_ARCH), arm)
-ifneq ($(TARGET_GCC_VERSION), 4.7)
+ifeq ($(TARGET_GCC_VERSION), 4.6)
LOCAL_CFLAGS += -Winline
endif # TARGET_GCC_VERSION
endif # TARGET_ARCH
@@ -58,25 +52,27 @@ LATIN_IME_CORE_SRC_FILES := \
correction.cpp \
dictionary.cpp \
dic_traverse_wrapper.cpp \
+ digraph_utils.cpp \
proximity_info.cpp \
proximity_info_params.cpp \
proximity_info_state.cpp \
proximity_info_state_utils.cpp \
unigram_dictionary.cpp \
words_priority_queue.cpp \
- suggest/core/dicnode/dic_node.cpp \
- suggest/core/dicnode/dic_nodes_cache.cpp \
- suggest/core/dicnode/dic_node_utils.cpp \
+ suggest/core/suggest.cpp \
+ $(addprefix suggest/core/dicnode/, \
+ dic_node.cpp \
+ dic_node_utils.cpp \
+ dic_nodes_cache.cpp) \
suggest/core/policy/weighting.cpp \
suggest/core/session/dic_traverse_session.cpp \
- suggest/core/suggest.cpp \
- suggest/policyimpl/typing/scoring_params.cpp \
- suggest/policyimpl/typing/typing_scoring.cpp \
- suggest/policyimpl/typing/typing_suggest_policy.cpp \
- suggest/policyimpl/typing/typing_traversal.cpp \
- suggest/policyimpl/typing/typing_weighting.cpp \
- suggest/gesture_suggest.cpp \
- suggest/typing_suggest.cpp
+ suggest/policyimpl/gesture/gesture_suggest_policy_factory.cpp \
+ $(addprefix suggest/policyimpl/typing/, \
+ scoring_params.cpp \
+ typing_scoring.cpp \
+ typing_suggest_policy.cpp \
+ typing_traversal.cpp \
+ typing_weighting.cpp)
LOCAL_SRC_FILES := \
$(LATIN_IME_JNI_SRC_FILES) \
@@ -131,6 +127,4 @@ include $(BUILD_SHARED_LIBRARY)
#################### Clean up the tmp vars
LATIN_IME_CORE_SRC_FILES :=
LATIN_IME_JNI_SRC_FILES :=
-LATIN_IME_GESTURE_IMPL_SRC_FILES :=
LATIN_IME_SRC_DIR :=
-LATIN_IME_SRC_FULLPATH_DIR :=
diff --git a/native/jni/jni_common.cpp b/native/jni/jni_common.cpp
index 1ea204102..8e5c50880 100644
--- a/native/jni/jni_common.cpp
+++ b/native/jni/jni_common.cpp
@@ -16,12 +16,12 @@
#define LOG_TAG "LatinIME: jni"
+#include "jni_common.h"
+
#include "com_android_inputmethod_keyboard_ProximityInfo.h"
#include "com_android_inputmethod_latin_BinaryDictionary.h"
#include "com_android_inputmethod_latin_DicTraverseSession.h"
#include "defines.h"
-#include "jni.h"
-#include "jni_common.h"
/*
* Returns the JNI version on success, -1 on failure.
diff --git a/native/jni/src/bigram_dictionary.cpp b/native/jni/src/bigram_dictionary.cpp
index 43e59a262..92890383a 100644
--- a/native/jni/src/bigram_dictionary.cpp
+++ b/native/jni/src/bigram_dictionary.cpp
@@ -39,7 +39,7 @@ BigramDictionary::~BigramDictionary() {
void BigramDictionary::addWordBigram(int *word, int length, int probability, int *bigramProbability,
int *bigramCodePoints, int *outputTypes) const {
word[length] = 0;
- if (DEBUG_DICT) {
+ if (DEBUG_DICT_FULL) {
#ifdef FLAG_DBG
char s[length + 1];
for (int i = 0; i <= length; i++) s[i] = static_cast<char>(word[i]);
@@ -57,7 +57,7 @@ void BigramDictionary::addWordBigram(int *word, int length, int probability, int
}
insertAt++;
}
- if (DEBUG_DICT) {
+ if (DEBUG_DICT_FULL) {
AKLOGI("Bigram: InsertAt -> %d MAX_RESULTS: %d", insertAt, MAX_RESULTS);
}
if (insertAt >= MAX_RESULTS) {
@@ -76,7 +76,7 @@ void BigramDictionary::addWordBigram(int *word, int length, int probability, int
*dest++ = *word++;
}
*dest = 0; // NULL terminate
- if (DEBUG_DICT) {
+ if (DEBUG_DICT_FULL) {
AKLOGI("Bigram: Added word at %d", insertAt);
}
}
diff --git a/native/jni/src/correction.cpp b/native/jni/src/correction.cpp
index 671507ee0..76234f840 100644
--- a/native/jni/src/correction.cpp
+++ b/native/jni/src/correction.cpp
@@ -954,7 +954,13 @@ inline static int editDistanceInternal(int *editDistanceTable, const int *before
// In dictionary.cpp, getSuggestion() method,
-// suggestion scores are computed using the below formula.
+// When USE_SUGGEST_INTERFACE_FOR_TYPING is true:
+// SUGGEST_INTERFACE_OUTPUT_SCALE was multiplied to the original suggestion scores to convert
+// them to integers.
+// score = (int)((original score) * SUGGEST_INTERFACE_OUTPUT_SCALE)
+// Undo the scaling here to recover the original score.
+// normalizedScore = ((float)score) / SUGGEST_INTERFACE_OUTPUT_SCALE
+// Otherwise: suggestion scores are computed using the below formula.
// original score
// := powf(mTypedLetterMultiplier (this is defined 2),
// (the number of matched characters between typed word and suggested word))
@@ -991,16 +997,20 @@ inline static int editDistanceInternal(int *editDistanceTable, const int *before
return 0.0f;
}
+ // add a weight based on edit distance.
+ // distance <= max(afterLength, beforeLength) == afterLength,
+ // so, 0 <= distance / afterLength <= 1
+ const float weight = 1.0f - static_cast<float>(distance) / static_cast<float>(afterLength);
+
+ if (USE_SUGGEST_INTERFACE_FOR_TYPING) {
+ return (static_cast<float>(score) / SUGGEST_INTERFACE_OUTPUT_SCALE) * weight;
+ }
const float maxScore = score >= S_INT_MAX ? static_cast<float>(S_INT_MAX)
: static_cast<float>(MAX_INITIAL_SCORE)
* powf(static_cast<float>(TYPED_LETTER_MULTIPLIER),
static_cast<float>(min(beforeLength, afterLength - spaceCount)))
* static_cast<float>(FULL_WORD_MULTIPLIER);
- // add a weight based on edit distance.
- // distance <= max(afterLength, beforeLength) == afterLength,
- // so, 0 <= distance / afterLength <= 1
- const float weight = 1.0f - static_cast<float>(distance) / static_cast<float>(afterLength);
return (static_cast<float>(score) / maxScore) * weight;
}
} // namespace latinime
diff --git a/native/jni/src/correction.h b/native/jni/src/correction.h
index f0d62102f..a9e9b48a6 100644
--- a/native/jni/src/correction.h
+++ b/native/jni/src/correction.h
@@ -307,7 +307,7 @@ inline void Correction::startToTraverseAllNodes() {
mNeedsToTraverseAllNodes = true;
}
-inline bool Correction::isSingleQuote(const int c) {
+AK_FORCE_INLINE bool Correction::isSingleQuote(const int c) {
const int userTypedChar = mProximityInfoState.getPrimaryCodePointAt(mInputIndex);
return (c == KEYCODE_SINGLE_QUOTE && userTypedChar != KEYCODE_SINGLE_QUOTE);
}
diff --git a/native/jni/src/defines.h b/native/jni/src/defines.h
index 6e098157d..a45691261 100644
--- a/native/jni/src/defines.h
+++ b/native/jni/src/defines.h
@@ -287,6 +287,7 @@ static inline void prof_out(void) {
#define CALIBRATE_SCORE_BY_TOUCH_COORDINATES true
#define SUGGEST_MULTIPLE_WORDS true
+#define USE_SUGGEST_INTERFACE_FOR_TYPING true
#define SUGGEST_INTERFACE_OUTPUT_SCALE 1000000.0f
// The following "rate"s are used as a multiplier before dividing by 100, so they are in percent.
diff --git a/native/jni/src/dictionary.cpp b/native/jni/src/dictionary.cpp
index 6deab36b6..ed6ddb517 100644
--- a/native/jni/src/dictionary.cpp
+++ b/native/jni/src/dictionary.cpp
@@ -16,14 +16,18 @@
#define LOG_TAG "LatinIME: dictionary.cpp"
+#include "dictionary.h"
+
+#include <map> // TODO: remove
#include <stdint.h>
#include "bigram_dictionary.h"
#include "binary_format.h"
#include "defines.h"
-#include "dictionary.h"
#include "dic_traverse_wrapper.h"
-#include "gesture_suggest.h"
+#include "suggest/core/suggest.h"
+#include "suggest/policyimpl/gesture/gesture_suggest_policy_factory.h"
+#include "suggest/policyimpl/typing/typing_suggest_policy_factory.h"
#include "unigram_dictionary.h"
namespace latinime {
@@ -34,13 +38,15 @@ Dictionary::Dictionary(void *dict, int dictSize, int mmapFd, int dictBufAdjust)
mDictSize(dictSize), mMmapFd(mmapFd), mDictBufAdjust(dictBufAdjust),
mUnigramDictionary(new UnigramDictionary(mOffsetDict, BinaryFormat::getFlags(mDict))),
mBigramDictionary(new BigramDictionary(mOffsetDict)),
- mGestureSuggest(new GestureSuggest()) {
+ mGestureSuggest(new Suggest(GestureSuggestPolicyFactory::getGestureSuggestPolicy())),
+ mTypingSuggest(new Suggest(TypingSuggestPolicyFactory::getTypingSuggestPolicy())) {
}
Dictionary::~Dictionary() {
delete mUnigramDictionary;
delete mBigramDictionary;
delete mGestureSuggest;
+ delete mTypingSuggest;
}
int Dictionary::getSuggestions(ProximityInfo *proximityInfo, void *traverseSession,
@@ -60,14 +66,26 @@ int Dictionary::getSuggestions(ProximityInfo *proximityInfo, void *traverseSessi
}
return result;
} else {
- std::map<int, int> bigramMap;
- uint8_t bigramFilter[BIGRAM_FILTER_BYTE_SIZE];
- mBigramDictionary->fillBigramAddressToProbabilityMapAndFilter(prevWordCodePoints,
- prevWordLength, &bigramMap, bigramFilter);
- result = mUnigramDictionary->getSuggestions(proximityInfo, xcoordinates, ycoordinates,
- inputCodePoints, inputSize, &bigramMap, bigramFilter, useFullEditDistance, outWords,
- frequencies, outputTypes);
- return result;
+ if (USE_SUGGEST_INTERFACE_FOR_TYPING) {
+ DicTraverseWrapper::initDicTraverseSession(
+ traverseSession, this, prevWordCodePoints, prevWordLength);
+ result = mTypingSuggest->getSuggestions(proximityInfo, traverseSession, xcoordinates,
+ ycoordinates, times, pointerIds, inputCodePoints, inputSize, commitPoint,
+ outWords, frequencies, spaceIndices, outputTypes);
+ if (DEBUG_DICT) {
+ DUMP_RESULT(outWords, frequencies);
+ }
+ return result;
+ } else {
+ std::map<int, int> bigramMap;
+ uint8_t bigramFilter[BIGRAM_FILTER_BYTE_SIZE];
+ mBigramDictionary->fillBigramAddressToProbabilityMapAndFilter(prevWordCodePoints,
+ prevWordLength, &bigramMap, bigramFilter);
+ result = mUnigramDictionary->getSuggestions(proximityInfo, xcoordinates, ycoordinates,
+ inputCodePoints, inputSize, &bigramMap, bigramFilter, useFullEditDistance,
+ outWords, frequencies, outputTypes);
+ return result;
+ }
}
}
diff --git a/native/jni/src/dictionary.h b/native/jni/src/dictionary.h
index 449b95ab6..8c6a7de52 100644
--- a/native/jni/src/dictionary.h
+++ b/native/jni/src/dictionary.h
@@ -79,6 +79,7 @@ class Dictionary {
const UnigramDictionary *mUnigramDictionary;
const BigramDictionary *mBigramDictionary;
SuggestInterface *mGestureSuggest;
+ SuggestInterface *mTypingSuggest;
};
} // namespace latinime
#endif // LATINIME_DICTIONARY_H
diff --git a/native/jni/src/digraph_utils.cpp b/native/jni/src/digraph_utils.cpp
new file mode 100644
index 000000000..8781c5077
--- /dev/null
+++ b/native/jni/src/digraph_utils.cpp
@@ -0,0 +1,93 @@
+/*
+ * 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.
+ */
+
+#include "binary_format.h"
+#include "defines.h"
+#include "digraph_utils.h"
+
+namespace latinime {
+
+const DigraphUtils::digraph_t DigraphUtils::GERMAN_UMLAUT_DIGRAPHS[] =
+ { { 'a', 'e', 0x00E4 }, // U+00E4 : LATIN SMALL LETTER A WITH DIAERESIS
+ { 'o', 'e', 0x00F6 }, // U+00F6 : LATIN SMALL LETTER O WITH DIAERESIS
+ { 'u', 'e', 0x00FC } }; // U+00FC : LATIN SMALL LETTER U WITH DIAERESIS
+const DigraphUtils::digraph_t DigraphUtils::FRENCH_LIGATURES_DIGRAPHS[] =
+ { { 'a', 'e', 0x00E6 }, // U+00E6 : LATIN SMALL LETTER AE
+ { 'o', 'e', 0x0153 } }; // U+0153 : LATIN SMALL LIGATURE OE
+
+/* static */ bool DigraphUtils::hasDigraphForCodePoint(
+ const int dictFlags, const int compositeGlyphCodePoint) {
+ if (DigraphUtils::getDigraphForCodePoint(dictFlags, compositeGlyphCodePoint)) {
+ return true;
+ }
+ return false;
+}
+
+// Retrieves the set of all digraphs associated with the given dictionary.
+// Returns the size of the digraph array, or 0 if none exist.
+/* static */ int DigraphUtils::getAllDigraphsForDictionaryAndReturnSize(
+ const int dictFlags, const DigraphUtils::digraph_t **digraphs) {
+ if (BinaryFormat::REQUIRES_GERMAN_UMLAUT_PROCESSING & dictFlags) {
+ *digraphs = DigraphUtils::GERMAN_UMLAUT_DIGRAPHS;
+ return NELEMS(DigraphUtils::GERMAN_UMLAUT_DIGRAPHS);
+ }
+ if (BinaryFormat::REQUIRES_FRENCH_LIGATURES_PROCESSING & dictFlags) {
+ *digraphs = DigraphUtils::FRENCH_LIGATURES_DIGRAPHS;
+ return NELEMS(DigraphUtils::FRENCH_LIGATURES_DIGRAPHS);
+ }
+ return 0;
+}
+
+// Returns the digraph codepoint for the given composite glyph codepoint and digraph codepoint index
+// (which specifies the first or second codepoint in the digraph).
+/* static */ int DigraphUtils::getDigraphCodePointForIndex(const int dictFlags,
+ const int compositeGlyphCodePoint, const DigraphCodePointIndex digraphCodePointIndex) {
+ if (digraphCodePointIndex == NOT_A_DIGRAPH_INDEX) {
+ return NOT_A_CODE_POINT;
+ }
+ const DigraphUtils::digraph_t *digraph =
+ DigraphUtils::getDigraphForCodePoint(dictFlags, compositeGlyphCodePoint);
+ if (!digraph) {
+ return NOT_A_CODE_POINT;
+ }
+ if (digraphCodePointIndex == FIRST_DIGRAPH_CODEPOINT) {
+ return digraph->first;
+ } else if (digraphCodePointIndex == SECOND_DIGRAPH_CODEPOINT) {
+ return digraph->second;
+ }
+ ASSERT(false);
+ return NOT_A_CODE_POINT;
+}
+
+/**
+ * Returns the digraph for the input composite glyph codepoint, or 0 if none exists.
+ * dictFlags: the dictionary flags needed to determine which digraphs are supported.
+ * compositeGlyphCodePoint: the method returns the digraph corresponding to this codepoint.
+ */
+/* static */ const DigraphUtils::digraph_t *DigraphUtils::getDigraphForCodePoint(
+ const int dictFlags, const int compositeGlyphCodePoint) {
+ const DigraphUtils::digraph_t *digraphs = 0;
+ const int digraphsSize =
+ DigraphUtils::getAllDigraphsForDictionaryAndReturnSize(dictFlags, &digraphs);
+ for (int i = 0; i < digraphsSize; i++) {
+ if (digraphs[i].compositeGlyph == compositeGlyphCodePoint) {
+ return &digraphs[i];
+ }
+ }
+ return 0;
+}
+
+} // namespace latinime
diff --git a/native/jni/src/digraph_utils.h b/native/jni/src/digraph_utils.h
new file mode 100644
index 000000000..6e364b67a
--- /dev/null
+++ b/native/jni/src/digraph_utils.h
@@ -0,0 +1,47 @@
+/*
+ * 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 DIGRAPH_UTILS_H
+#define DIGRAPH_UTILS_H
+
+namespace latinime {
+
+class DigraphUtils {
+ public:
+ typedef enum {
+ NOT_A_DIGRAPH_INDEX,
+ FIRST_DIGRAPH_CODEPOINT,
+ SECOND_DIGRAPH_CODEPOINT
+ } DigraphCodePointIndex;
+
+ typedef struct { int first; int second; int compositeGlyph; } digraph_t;
+
+ static bool hasDigraphForCodePoint(const int dictFlags, const int compositeGlyphCodePoint);
+ static int getAllDigraphsForDictionaryAndReturnSize(
+ const int dictFlags, const digraph_t **digraphs);
+ static int getDigraphCodePointForIndex(const int dictFlags, const int compositeGlyphCodePoint,
+ const DigraphCodePointIndex digraphCodePointIndex);
+
+ private:
+ DISALLOW_IMPLICIT_CONSTRUCTORS(DigraphUtils);
+ static const digraph_t *getDigraphForCodePoint(
+ const int dictFlags, const int compositeGlyphCodePoint);
+
+ static const digraph_t GERMAN_UMLAUT_DIGRAPHS[];
+ static const digraph_t FRENCH_LIGATURES_DIGRAPHS[];
+};
+} // namespace latinime
+#endif // DIGRAPH_UTILS_H
diff --git a/native/jni/src/suggest/core/dictionary/shortcut_utils.h b/native/jni/src/suggest/core/dictionary/shortcut_utils.h
index e592136cc..c411408ec 100644
--- a/native/jni/src/suggest/core/dictionary/shortcut_utils.h
+++ b/native/jni/src/suggest/core/dictionary/shortcut_utils.h
@@ -18,7 +18,7 @@
#define LATINIME_SHORTCUT_UTILS
#include "defines.h"
-#include "dic_node_utils.h"
+#include "suggest/core/dicnode/dic_node_utils.h"
#include "terminal_attributes.h"
namespace latinime {
diff --git a/native/jni/src/suggest/core/policy/traversal.h b/native/jni/src/suggest/core/policy/traversal.h
index 1d5082ff8..02c358aec 100644
--- a/native/jni/src/suggest/core/policy/traversal.h
+++ b/native/jni/src/suggest/core/policy/traversal.h
@@ -20,6 +20,9 @@
#include "defines.h"
namespace latinime {
+
+class DicTraverseSession;
+
class Traversal {
public:
virtual int getMaxPointerCount() const = 0;
diff --git a/native/jni/src/suggest/core/policy/weighting.cpp b/native/jni/src/suggest/core/policy/weighting.cpp
index 4d08fa0fa..e62b70423 100644
--- a/native/jni/src/suggest/core/policy/weighting.cpp
+++ b/native/jni/src/suggest/core/policy/weighting.cpp
@@ -14,14 +14,15 @@
* limitations under the License.
*/
+#include "suggest/core/policy/weighting.h"
+
#include "char_utils.h"
#include "defines.h"
-#include "dic_node.h"
-#include "dic_node_profiler.h"
-#include "dic_node_utils.h"
-#include "dic_traverse_session.h"
#include "hash_map_compat.h"
-#include "weighting.h"
+#include "suggest/core/dicnode/dic_node.h"
+#include "suggest/core/dicnode/dic_node_profiler.h"
+#include "suggest/core/dicnode/dic_node_utils.h"
+#include "suggest/core/session/dic_traverse_session.h"
namespace latinime {
diff --git a/native/jni/src/suggest/core/policy/weighting.h b/native/jni/src/suggest/core/policy/weighting.h
index 83a0f4b45..b92dbe278 100644
--- a/native/jni/src/suggest/core/policy/weighting.h
+++ b/native/jni/src/suggest/core/policy/weighting.h
@@ -18,6 +18,7 @@
#define LATINIME_WEIGHTING_H
#include "defines.h"
+#include "hash_map_compat.h"
namespace latinime {
diff --git a/native/jni/src/suggest/core/session/dic_traverse_session.cpp b/native/jni/src/suggest/core/session/dic_traverse_session.cpp
index 1f781dd43..ef6616e40 100644
--- a/native/jni/src/suggest/core/session/dic_traverse_session.cpp
+++ b/native/jni/src/suggest/core/session/dic_traverse_session.cpp
@@ -14,12 +14,13 @@
* limitations under the License.
*/
+#include "suggest/core/session/dic_traverse_session.h"
+
#include "defines.h"
#include "dictionary.h"
-#include "dic_node_utils.h"
-#include "dic_traverse_session.h"
#include "dic_traverse_wrapper.h"
#include "jni.h"
+#include "suggest/core/dicnode/dic_node_utils.h"
namespace latinime {
diff --git a/native/jni/src/suggest/core/session/dic_traverse_session.h b/native/jni/src/suggest/core/session/dic_traverse_session.h
index af036f82b..62e1d1ab9 100644
--- a/native/jni/src/suggest/core/session/dic_traverse_session.h
+++ b/native/jni/src/suggest/core/session/dic_traverse_session.h
@@ -21,10 +21,10 @@
#include <vector>
#include "defines.h"
-#include "dic_nodes_cache.h"
#include "hash_map_compat.h"
#include "jni.h"
#include "proximity_info_state.h"
+#include "suggest/core/dicnode/dic_nodes_cache.h"
namespace latinime {
diff --git a/native/jni/src/suggest/core/suggest.cpp b/native/jni/src/suggest/core/suggest.cpp
index 7fba1d504..1e97a9176 100644
--- a/native/jni/src/suggest/core/suggest.cpp
+++ b/native/jni/src/suggest/core/suggest.cpp
@@ -14,18 +14,20 @@
* limitations under the License.
*/
+#include "suggest/core/suggest.h"
+
#include "char_utils.h"
#include "dictionary.h"
-#include "dic_node_priority_queue.h"
-#include "dic_node_vector.h"
-#include "dic_traverse_session.h"
#include "proximity_info.h"
-#include "scoring.h"
-#include "shortcut_utils.h"
-#include "suggest.h"
+#include "suggest/core/dicnode/dic_node.h"
+#include "suggest/core/dicnode/dic_node_priority_queue.h"
+#include "suggest/core/dicnode/dic_node_vector.h"
+#include "suggest/core/dictionary/shortcut_utils.h"
+#include "suggest/core/policy/scoring.h"
+#include "suggest/core/policy/traversal.h"
+#include "suggest/core/policy/weighting.h"
+#include "suggest/core/session/dic_traverse_session.h"
#include "terminal_attributes.h"
-#include "traversal.h"
-#include "weighting.h"
namespace latinime {
diff --git a/native/jni/src/suggest/core/suggest.h b/native/jni/src/suggest/core/suggest.h
index 75d646bdd..a1e7e7a94 100644
--- a/native/jni/src/suggest/core/suggest.h
+++ b/native/jni/src/suggest/core/suggest.h
@@ -18,8 +18,8 @@
#define LATINIME_SUGGEST_IMPL_H
#include "defines.h"
-#include "suggest_interface.h"
-#include "suggest_policy.h"
+#include "suggest/core/suggest_interface.h"
+#include "suggest/core/policy/suggest_policy.h"
namespace latinime {
diff --git a/native/jni/src/suggest/suggest_interface.h b/native/jni/src/suggest/core/suggest_interface.h
index 0bb85d7e5..0bb85d7e5 100644
--- a/native/jni/src/suggest/suggest_interface.h
+++ b/native/jni/src/suggest/core/suggest_interface.h
diff --git a/native/jni/src/suggest/gesture_suggest.h b/native/jni/src/suggest/gesture_suggest.h
deleted file mode 100644
index 82c3a69ad..000000000
--- a/native/jni/src/suggest/gesture_suggest.h
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Copyright (C) 2012 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_GESTURE_SUGGEST_H
-#define LATINIME_GESTURE_SUGGEST_H
-
-#include "defines.h"
-#include "suggest_interface.h"
-
-namespace latinime {
-
-class ProximityInfo;
-
-class GestureSuggest : public SuggestInterface {
- public:
- GestureSuggest() : mSuggestInterface(getGestureSuggestInstance()) {}
-
- virtual ~GestureSuggest();
-
- int getSuggestions(ProximityInfo *pInfo, void *traverseSession, int *inputXs, int *inputYs,
- int *times, int *pointerIds, int *inputCodePoints, int inputSize, int commitPoint,
- int *outWords, int *frequencies, int *outputIndices, int *outputTypes) const {
- if (!mSuggestInterface) {
- return 0;
- }
- return mSuggestInterface->getSuggestions(pInfo, traverseSession, inputXs, inputYs, times,
- pointerIds, inputCodePoints, inputSize, commitPoint, outWords, frequencies,
- outputIndices, outputTypes);
- }
-
- static void setGestureSuggestFactoryMethod(SuggestInterface *(*factoryMethod)()) {
- sGestureSuggestFactoryMethod = factoryMethod;
- }
-
- private:
- DISALLOW_COPY_AND_ASSIGN(GestureSuggest);
- static SuggestInterface *getGestureSuggestInstance() {
- if (!sGestureSuggestFactoryMethod) {
- return 0;
- }
- return sGestureSuggestFactoryMethod();
- }
-
- static SuggestInterface *(*sGestureSuggestFactoryMethod)();
- SuggestInterface *mSuggestInterface;
-};
-} // namespace latinime
-#endif // LATINIME_GESTURE_SUGGEST_H
diff --git a/native/jni/src/suggest/typing_suggest.cpp b/native/jni/src/suggest/policyimpl/gesture/gesture_suggest_policy_factory.cpp
index 56bd5b69a..6d3173937 100644
--- a/native/jni/src/suggest/typing_suggest.cpp
+++ b/native/jni/src/suggest/policyimpl/gesture/gesture_suggest_policy_factory.cpp
@@ -14,12 +14,8 @@
* limitations under the License.
*/
-#include "typing_suggest.h"
+#include "gesture_suggest_policy_factory.h"
namespace latinime {
- SuggestInterface *(*TypingSuggest::sTypingSuggestFactoryMethod)() = 0;
-
- TypingSuggest::~TypingSuggest() {
- delete mSuggestInterface;
- }
+ const SuggestPolicy *(*GestureSuggestPolicyFactory::sGestureSuggestFactoryMethod)() = 0;
} // namespace latinime
diff --git a/native/jni/src/suggest/policyimpl/gesture/gesture_suggest_policy_factory.h b/native/jni/src/suggest/policyimpl/gesture/gesture_suggest_policy_factory.h
new file mode 100644
index 000000000..509b01fc0
--- /dev/null
+++ b/native/jni/src/suggest/policyimpl/gesture/gesture_suggest_policy_factory.h
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2012 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_GESTURE_SUGGEST_POLICY_FACTORY_H
+#define LATINIME_GESTURE_SUGGEST_POLICY_FACTORY_H
+
+#include "defines.h"
+
+namespace latinime {
+
+class SuggestPolicy;
+
+class GestureSuggestPolicyFactory {
+ public:
+ static void setGestureSuggestPolicyFactoryMethod(const SuggestPolicy *(*factoryMethod)()) {
+ sGestureSuggestFactoryMethod = factoryMethod;
+ }
+
+ static const SuggestPolicy *getGestureSuggestPolicy() {
+ if (!sGestureSuggestFactoryMethod) {
+ return 0;
+ }
+ return sGestureSuggestFactoryMethod();
+ }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(GestureSuggestPolicyFactory);
+ static const SuggestPolicy *(*sGestureSuggestFactoryMethod)();
+};
+} // namespace latinime
+#endif // LATINIME_GESTURE_SUGGEST_POLICY_FACTORY_H
diff --git a/native/jni/src/suggest/policyimpl/typing/scoring_params.cpp b/native/jni/src/suggest/policyimpl/typing/scoring_params.cpp
index 90985d0fe..0fa684f01 100644
--- a/native/jni/src/suggest/policyimpl/typing/scoring_params.cpp
+++ b/native/jni/src/suggest/policyimpl/typing/scoring_params.cpp
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-#include "scoring_params.h"
+#include "suggest/policyimpl/typing/scoring_params.h"
namespace latinime {
// TODO: RENAME all
diff --git a/native/jni/src/suggest/policyimpl/typing/typing_scoring.cpp b/native/jni/src/suggest/policyimpl/typing/typing_scoring.cpp
index 53f68f20f..d8c6175e2 100644
--- a/native/jni/src/suggest/policyimpl/typing/typing_scoring.cpp
+++ b/native/jni/src/suggest/policyimpl/typing/typing_scoring.cpp
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-#include "typing_scoring.h"
+#include "suggest/policyimpl/typing/typing_scoring.h"
namespace latinime {
const TypingScoring TypingScoring::sInstance;
diff --git a/native/jni/src/suggest/policyimpl/typing/typing_scoring.h b/native/jni/src/suggest/policyimpl/typing/typing_scoring.h
index ed941f0ae..90e2133e7 100644
--- a/native/jni/src/suggest/policyimpl/typing/typing_scoring.h
+++ b/native/jni/src/suggest/policyimpl/typing/typing_scoring.h
@@ -18,8 +18,8 @@
#define LATINIME_TYPING_SCORING_H
#include "defines.h"
-#include "scoring.h"
-#include "scoring_params.h"
+#include "suggest/core/policy/scoring.h"
+#include "suggest/policyimpl/typing/scoring_params.h"
namespace latinime {
diff --git a/native/jni/src/suggest/policyimpl/typing/typing_suggest_policy.cpp b/native/jni/src/suggest/policyimpl/typing/typing_suggest_policy.cpp
index ebba37531..0c2763967 100644
--- a/native/jni/src/suggest/policyimpl/typing/typing_suggest_policy.cpp
+++ b/native/jni/src/suggest/policyimpl/typing/typing_suggest_policy.cpp
@@ -14,29 +14,8 @@
* limitations under the License.
*/
-#include "suggest.h"
-#include "typing_suggest.h"
-#include "typing_suggest_policy.h"
+#include "suggest/policyimpl/typing/typing_suggest_policy.h"
namespace latinime {
-
const TypingSuggestPolicy TypingSuggestPolicy::sInstance;
-
-// A factory method for a "typing" Suggest instance
-static SuggestInterface *getTypingSuggestInstance() {
- return new Suggest(TypingSuggestPolicy::getInstance());
-}
-
-// An ad-hoc internal class to register the factory method getTypingSuggestInstance() defined above
-class TypingSuggestFactoryRegisterer {
- public:
- TypingSuggestFactoryRegisterer() {
- TypingSuggest::setTypingSuggestFactoryMethod(getTypingSuggestInstance);
- }
- private:
- DISALLOW_COPY_AND_ASSIGN(TypingSuggestFactoryRegisterer);
-};
-
-// To invoke the TypingSuggestFactoryRegisterer's constructor in the global constructor
-static TypingSuggestFactoryRegisterer typingSuggestFactoryregisterer;
} // namespace latinime
diff --git a/native/jni/src/suggest/policyimpl/typing/typing_suggest_policy.h b/native/jni/src/suggest/policyimpl/typing/typing_suggest_policy.h
index 55668fc25..35f48097c 100644
--- a/native/jni/src/suggest/policyimpl/typing/typing_suggest_policy.h
+++ b/native/jni/src/suggest/policyimpl/typing/typing_suggest_policy.h
@@ -18,10 +18,10 @@
#define LATINIME_TYPING_SUGGEST_POLICY_H
#include "defines.h"
-#include "suggest_policy.h"
-#include "typing_scoring.h"
-#include "typing_traversal.h"
-#include "typing_weighting.h"
+#include "suggest/core/policy/suggest_policy.h"
+#include "suggest/policyimpl/typing/typing_scoring.h"
+#include "suggest/policyimpl/typing/typing_traversal.h"
+#include "suggest/policyimpl/typing/typing_weighting.h"
namespace latinime {
diff --git a/native/jni/src/suggest/gesture_suggest.cpp b/native/jni/src/suggest/policyimpl/typing/typing_suggest_policy_factory.h
index fce5621d5..a67b45b1b 100644
--- a/native/jni/src/suggest/gesture_suggest.cpp
+++ b/native/jni/src/suggest/policyimpl/typing/typing_suggest_policy_factory.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2012 The Android Open Source Project
+ * 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.
@@ -14,12 +14,24 @@
* limitations under the License.
*/
-#include "gesture_suggest.h"
+#ifndef LATINIME_TYPING_SUGGEST_POLICY_FACTORY_H
+#define LATINIME_TYPING_SUGGEST_POLICY_FACTORY_H
+
+#include "defines.h"
+#include "typing_suggest_policy.h"
namespace latinime {
- SuggestInterface *(*GestureSuggest::sGestureSuggestFactoryMethod)() = 0;
- GestureSuggest::~GestureSuggest() {
- delete mSuggestInterface;
+class SuggestPolicy;
+
+class TypingSuggestPolicyFactory {
+ public:
+ static const SuggestPolicy *getTypingSuggestPolicy() {
+ return TypingSuggestPolicy::getInstance();
}
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(TypingSuggestPolicyFactory);
+};
} // namespace latinime
+#endif // LATINIME_TYPING_SUGGEST_POLICY_FACTORY_H
diff --git a/native/jni/src/suggest/policyimpl/typing/typing_traversal.cpp b/native/jni/src/suggest/policyimpl/typing/typing_traversal.cpp
index 68c614e77..66f8ba9fa 100644
--- a/native/jni/src/suggest/policyimpl/typing/typing_traversal.cpp
+++ b/native/jni/src/suggest/policyimpl/typing/typing_traversal.cpp
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-#include "typing_traversal.h"
+#include "suggest/policyimpl/typing/typing_traversal.h"
namespace latinime {
const bool TypingTraversal::CORRECT_OMISSION = true;
diff --git a/native/jni/src/suggest/policyimpl/typing/typing_traversal.h b/native/jni/src/suggest/policyimpl/typing/typing_traversal.h
index 16153f8bb..f22029a2c 100644
--- a/native/jni/src/suggest/policyimpl/typing/typing_traversal.h
+++ b/native/jni/src/suggest/policyimpl/typing/typing_traversal.h
@@ -21,12 +21,12 @@
#include "char_utils.h"
#include "defines.h"
-#include "dic_node.h"
-#include "dic_node_vector.h"
-#include "dic_traverse_session.h"
#include "proximity_info_state.h"
-#include "scoring_params.h"
-#include "traversal.h"
+#include "suggest/core/dicnode/dic_node.h"
+#include "suggest/core/dicnode/dic_node_vector.h"
+#include "suggest/core/policy/traversal.h"
+#include "suggest/core/session/dic_traverse_session.h"
+#include "suggest/policyimpl/typing/scoring_params.h"
namespace latinime {
class TypingTraversal : public Traversal {
diff --git a/native/jni/src/suggest/policyimpl/typing/typing_weighting.cpp b/native/jni/src/suggest/policyimpl/typing/typing_weighting.cpp
index 6e4b2fb6a..1500341bd 100644
--- a/native/jni/src/suggest/policyimpl/typing/typing_weighting.cpp
+++ b/native/jni/src/suggest/policyimpl/typing/typing_weighting.cpp
@@ -14,9 +14,10 @@
* limitations under the License.
*/
-#include "dic_node.h"
-#include "scoring_params.h"
-#include "typing_weighting.h"
+#include "suggest/policyimpl/typing/typing_weighting.h"
+
+#include "suggest/core/dicnode/dic_node.h"
+#include "suggest/policyimpl/typing/scoring_params.h"
namespace latinime {
const TypingWeighting TypingWeighting::sInstance;
diff --git a/native/jni/src/suggest/policyimpl/typing/typing_weighting.h b/native/jni/src/suggest/policyimpl/typing/typing_weighting.h
index e8075f41a..52d54eb0f 100644
--- a/native/jni/src/suggest/policyimpl/typing/typing_weighting.h
+++ b/native/jni/src/suggest/policyimpl/typing/typing_weighting.h
@@ -18,9 +18,10 @@
#define LATINIME_TYPING_WEIGHTING_H
#include "defines.h"
-#include "dic_node_utils.h"
-#include "dic_traverse_session.h"
-#include "weighting.h"
+#include "suggest/core/dicnode/dic_node_utils.h"
+#include "suggest/core/policy/weighting.h"
+#include "suggest/core/session/dic_traverse_session.h"
+#include "suggest/policyimpl/typing/scoring_params.h"
namespace latinime {
diff --git a/native/jni/src/suggest/typing_suggest.h b/native/jni/src/suggest/typing_suggest.h
deleted file mode 100644
index 678037aa2..000000000
--- a/native/jni/src/suggest/typing_suggest.h
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Copyright (C) 2012 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_TYPING_SUGGEST_H
-#define LATINIME_TYPING_SUGGEST_H
-
-#include "defines.h"
-#include "suggest_interface.h"
-
-namespace latinime {
-
-class ProximityInfo;
-
-class TypingSuggest : public SuggestInterface {
- public:
- TypingSuggest() : mSuggestInterface(getTypingSuggestInstance()) {}
-
- virtual ~TypingSuggest();
-
- int getSuggestions(ProximityInfo *pInfo, void *traverseSession, int *inputXs, int *inputYs,
- int *times, int *pointerIds, int *inputCodePoints, int inputSize, int commitPoint,
- int *outWords, int *frequencies, int *outputIndices, int *outputTypes) const {
- if (!mSuggestInterface) {
- return 0;
- }
- return mSuggestInterface->getSuggestions(pInfo, traverseSession, inputXs, inputYs, times,
- pointerIds, inputCodePoints, inputSize, commitPoint, outWords, frequencies,
- outputIndices, outputTypes);
- }
-
- static void setTypingSuggestFactoryMethod(SuggestInterface *(*factoryMethod)()) {
- sTypingSuggestFactoryMethod = factoryMethod;
- }
-
- private:
- DISALLOW_COPY_AND_ASSIGN(TypingSuggest);
- static SuggestInterface *getTypingSuggestInstance() {
- if (!sTypingSuggestFactoryMethod) {
- return 0;
- }
- return sTypingSuggestFactoryMethod();
- }
-
- static SuggestInterface *(*sTypingSuggestFactoryMethod)();
- SuggestInterface *mSuggestInterface;
-};
-} // namespace latinime
-#endif // LATINIME_TYPING_SUGGEST_H
diff --git a/native/jni/src/unigram_dictionary.cpp b/native/jni/src/unigram_dictionary.cpp
index 80ba412a3..33795cade 100644
--- a/native/jni/src/unigram_dictionary.cpp
+++ b/native/jni/src/unigram_dictionary.cpp
@@ -22,6 +22,7 @@
#include "char_utils.h"
#include "defines.h"
#include "dictionary.h"
+#include "digraph_utils.h"
#include "proximity_info.h"
#include "terminal_attributes.h"
#include "unigram_dictionary.h"
@@ -30,15 +31,6 @@
namespace latinime {
-const UnigramDictionary::digraph_t UnigramDictionary::GERMAN_UMLAUT_DIGRAPHS[] =
- { { 'a', 'e', 0x00E4 }, // U+00E4 : LATIN SMALL LETTER A WITH DIAERESIS
- { 'o', 'e', 0x00F6 }, // U+00F6 : LATIN SMALL LETTER O WITH DIAERESIS
- { 'u', 'e', 0x00FC } }; // U+00FC : LATIN SMALL LETTER U WITH DIAERESIS
-
-const UnigramDictionary::digraph_t UnigramDictionary::FRENCH_LIGATURES_DIGRAPHS[] =
- { { 'a', 'e', 0x00E6 }, // U+00E6 : LATIN SMALL LETTER AE
- { 'o', 'e', 0x0153 } }; // U+0153 : LATIN SMALL LIGATURE OE
-
// TODO: check the header
UnigramDictionary::UnigramDictionary(const uint8_t *const streamStart, const unsigned int flags)
: DICT_ROOT(streamStart), ROOT_POS(0),
@@ -58,7 +50,7 @@ static void addWord(int *word, int length, int probability, WordsPriorityQueue *
// Return the replacement code point for a digraph, or 0 if none.
int UnigramDictionary::getDigraphReplacement(const int *codes, const int i, const int inputSize,
- const digraph_t *const digraphs, const unsigned int digraphsSize) const {
+ const DigraphUtils::digraph_t *const digraphs, const unsigned int digraphsSize) const {
// There can't be a digraph if we don't have at least 2 characters to examine
if (i + 2 > inputSize) return false;
@@ -74,7 +66,7 @@ int UnigramDictionary::getDigraphReplacement(const int *codes, const int i, cons
// It's an interesting digraph if the second char matches too.
if (digraphs[lastDigraphIndex].second == codes[i + 1]) {
- return digraphs[lastDigraphIndex].replacement;
+ return digraphs[lastDigraphIndex].compositeGlyph;
} else {
return 0;
}
@@ -93,7 +85,7 @@ void UnigramDictionary::getWordWithDigraphSuggestionsRec(ProximityInfo *proximit
const bool useFullEditDistance, const int *codesSrc,
const int codesRemain, const int currentDepth, int *codesDest, Correction *correction,
WordsPriorityQueuePool *queuePool,
- const digraph_t *const digraphs, const unsigned int digraphsSize) const {
+ const DigraphUtils::digraph_t *const digraphs, const unsigned int digraphsSize) const {
ASSERT(sizeof(codesDest[0]) == sizeof(codesSrc[0]));
ASSERT(sizeof(xCoordinatesBuffer[0]) == sizeof(xcoordinates[0]));
ASSERT(sizeof(yCoordinatesBuffer[0]) == sizeof(ycoordinates[0]));
@@ -169,7 +161,10 @@ int UnigramDictionary::getSuggestions(ProximityInfo *proximityInfo, const int *x
queuePool.clearAll();
Correction masterCorrection;
masterCorrection.resetCorrection();
- if (BinaryFormat::REQUIRES_GERMAN_UMLAUT_PROCESSING & FLAGS)
+ const DigraphUtils::digraph_t *digraphs = 0;
+ const int digraphsSize =
+ DigraphUtils::getAllDigraphsForDictionaryAndReturnSize(FLAGS, &digraphs);
+ if (digraphsSize > 0)
{ // Incrementally tune the word and try all possibilities
int codesBuffer[sizeof(*inputCodePoints) * inputSize];
int xCoordinatesBuffer[inputSize];
@@ -177,15 +172,7 @@ int UnigramDictionary::getSuggestions(ProximityInfo *proximityInfo, const int *x
getWordWithDigraphSuggestionsRec(proximityInfo, xcoordinates, ycoordinates, codesBuffer,
xCoordinatesBuffer, yCoordinatesBuffer, inputSize, bigramMap, bigramFilter,
useFullEditDistance, inputCodePoints, inputSize, 0, codesBuffer, &masterCorrection,
- &queuePool, GERMAN_UMLAUT_DIGRAPHS, NELEMS(GERMAN_UMLAUT_DIGRAPHS));
- } else if (BinaryFormat::REQUIRES_FRENCH_LIGATURES_PROCESSING & FLAGS) {
- int codesBuffer[sizeof(*inputCodePoints) * inputSize];
- int xCoordinatesBuffer[inputSize];
- int yCoordinatesBuffer[inputSize];
- getWordWithDigraphSuggestionsRec(proximityInfo, xcoordinates, ycoordinates, codesBuffer,
- xCoordinatesBuffer, yCoordinatesBuffer, inputSize, bigramMap, bigramFilter,
- useFullEditDistance, inputCodePoints, inputSize, 0, codesBuffer, &masterCorrection,
- &queuePool, FRENCH_LIGATURES_DIGRAPHS, NELEMS(FRENCH_LIGATURES_DIGRAPHS));
+ &queuePool, digraphs, digraphsSize);
} else { // Normal processing
getWordSuggestions(proximityInfo, xcoordinates, ycoordinates, inputCodePoints, inputSize,
bigramMap, bigramFilter, useFullEditDistance, &masterCorrection, &queuePool);
diff --git a/native/jni/src/unigram_dictionary.h b/native/jni/src/unigram_dictionary.h
index c1955e8bb..1a01758fe 100644
--- a/native/jni/src/unigram_dictionary.h
+++ b/native/jni/src/unigram_dictionary.h
@@ -20,6 +20,7 @@
#include <map>
#include <stdint.h>
#include "defines.h"
+#include "digraph_utils.h"
namespace latinime {
@@ -29,8 +30,6 @@ class TerminalAttributes;
class WordsPriorityQueuePool;
class UnigramDictionary {
- typedef struct { int first; int second; int replacement; } digraph_t;
-
public:
// Error tolerances
static const int DEFAULT_MAX_ERRORS = 2;
@@ -57,13 +56,13 @@ class UnigramDictionary {
const bool useFullEditDistance, Correction *correction,
WordsPriorityQueuePool *queuePool) const;
int getDigraphReplacement(const int *codes, const int i, const int inputSize,
- const digraph_t *const digraphs, const unsigned int digraphsSize) const;
+ const DigraphUtils::digraph_t *const digraphs, const unsigned int digraphsSize) const;
void getWordWithDigraphSuggestionsRec(ProximityInfo *proximityInfo, const int *xcoordinates,
const int *ycoordinates, const int *codesBuffer, int *xCoordinatesBuffer,
int *yCoordinatesBuffer, const int codesBufferSize, const std::map<int, int> *bigramMap,
const uint8_t *bigramFilter, const bool useFullEditDistance, const int *codesSrc,
const int codesRemain, const int currentDepth, int *codesDest, Correction *correction,
- WordsPriorityQueuePool *queuePool, const digraph_t *const digraphs,
+ WordsPriorityQueuePool *queuePool, const DigraphUtils::digraph_t *const digraphs,
const unsigned int digraphsSize) const;
void initSuggestions(ProximityInfo *proximityInfo, const int *xcoordinates,
const int *ycoordinates, const int *codes, const int inputSize,
@@ -111,9 +110,6 @@ class UnigramDictionary {
const int ROOT_POS;
const int MAX_DIGRAPH_SEARCH_DEPTH;
const int FLAGS;
-
- static const digraph_t GERMAN_UMLAUT_DIGRAPHS[];
- static const digraph_t FRENCH_LIGATURES_DIGRAPHS[];
};
} // namespace latinime
#endif // LATINIME_UNIGRAM_DICTIONARY_H