diff options
9 files changed, 42 insertions, 32 deletions
diff --git a/native/jni/src/suggest/core/dictionary/dictionary.cpp b/native/jni/src/suggest/core/dictionary/dictionary.cpp index ffa96e167..c26e3aad6 100644 --- a/native/jni/src/suggest/core/dictionary/dictionary.cpp +++ b/native/jni/src/suggest/core/dictionary/dictionary.cpp @@ -37,7 +37,7 @@ const int Dictionary::HEADER_ATTRIBUTE_BUFFER_SIZE = 32; Dictionary::Dictionary(JNIEnv *env, DictionaryStructureWithBufferPolicy::StructurePolicyPtr dictionaryStructureWithBufferPolicy) : mDictionaryStructureWithBufferPolicy(std::move(dictionaryStructureWithBufferPolicy)), - mBigramDictionary(new BigramDictionary(mDictionaryStructureWithBufferPolicy.get())), + mBigramDictionary(mDictionaryStructureWithBufferPolicy.get()), mGestureSuggest(new Suggest(GestureSuggestPolicyFactory::getGestureSuggestPolicy())), mTypingSuggest(new Suggest(TypingSuggestPolicyFactory::getTypingSuggestPolicy())) { logDictionaryInfo(env); @@ -78,7 +78,7 @@ void Dictionary::getPredictions(const int *word, int length, SuggestionResults *const outSuggestionResults) const { TimeKeeper::setCurrentTime(); if (length <= 0) return; - mBigramDictionary->getPredictions(word, length, outSuggestionResults); + mBigramDictionary.getPredictions(word, length, outSuggestionResults); } int Dictionary::getProbability(const int *word, int length) const { @@ -94,7 +94,7 @@ int Dictionary::getProbability(const int *word, int length) const { int Dictionary::getBigramProbability(const int *word0, int length0, const int *word1, int length1) const { TimeKeeper::setCurrentTime(); - return mBigramDictionary->getBigramProbability(word0, length0, word1, length1); + return mBigramDictionary.getBigramProbability(word0, length0, word1, length1); } void Dictionary::addUnigramWord(const int *const word, const int length, const int probability, diff --git a/native/jni/src/suggest/core/dictionary/dictionary.h b/native/jni/src/suggest/core/dictionary/dictionary.h index 2dea9fff8..ce032fceb 100644 --- a/native/jni/src/suggest/core/dictionary/dictionary.h +++ b/native/jni/src/suggest/core/dictionary/dictionary.h @@ -109,14 +109,13 @@ class Dictionary { private: DISALLOW_IMPLICIT_CONSTRUCTORS(Dictionary); - typedef std::unique_ptr<BigramDictionary> BigramDictionaryPtr; typedef std::unique_ptr<SuggestInterface> SuggestInterfacePtr; static const int HEADER_ATTRIBUTE_BUFFER_SIZE; const DictionaryStructureWithBufferPolicy::StructurePolicyPtr mDictionaryStructureWithBufferPolicy; - const BigramDictionaryPtr mBigramDictionary; + const BigramDictionary mBigramDictionary; const SuggestInterfacePtr mGestureSuggest; const SuggestInterfacePtr mTypingSuggest; diff --git a/native/jni/src/suggest/policyimpl/dictionary/structure/v2/patricia_trie_policy.cpp b/native/jni/src/suggest/policyimpl/dictionary/structure/v2/patricia_trie_policy.cpp index 84a6ccf33..4e795f82c 100644 --- a/native/jni/src/suggest/policyimpl/dictionary/structure/v2/patricia_trie_policy.cpp +++ b/native/jni/src/suggest/policyimpl/dictionary/structure/v2/patricia_trie_policy.cpp @@ -349,13 +349,14 @@ const WordProperty PatriciaTriePolicy::getWordProperty(const int *const codePoin // Skip the entry if the entry has been deleted. This never happens for ver2 dicts. if (bigramsIt.getBigramPos() != NOT_A_DICT_POS) { int word1Probability = NOT_A_PROBABILITY; - int word1CodePointCount = getCodePointsAndProbabilityAndReturnCodePointCount( + const int word1CodePointCount = getCodePointsAndProbabilityAndReturnCodePointCount( bigramsIt.getBigramPos(), MAX_WORD_LENGTH, bigramWord1CodePoints, &word1Probability); - std::vector<int> word1(bigramWord1CodePoints, + const std::vector<int> word1(bigramWord1CodePoints, bigramWord1CodePoints + word1CodePointCount); - bigrams.push_back(WordProperty::BigramProperty(&word1, bigramsIt.getProbability(), - NOT_A_TIMESTAMP /* timestamp */, 0 /* level */, 0 /* count */)); + const int probability = getProbability(word1Probability, bigramsIt.getProbability()); + bigrams.emplace_back(&word1, probability, + NOT_A_TIMESTAMP /* timestamp */, 0 /* level */, 0 /* count */); } } // Fetch shortcut information. @@ -371,12 +372,11 @@ const WordProperty PatriciaTriePolicy::getWordProperty(const int *const codePoin hasNext = ShortcutListReadingUtils::hasNext(shortcutFlags); const int shortcutTargetLength = ShortcutListReadingUtils::readShortcutTarget( mDictRoot, MAX_WORD_LENGTH, shortcutTargetCodePoints, &shortcutPos); - std::vector<int> shortcutTarget(shortcutTargetCodePoints, + const std::vector<int> shortcutTarget(shortcutTargetCodePoints, shortcutTargetCodePoints + shortcutTargetLength); const int shortcutProbability = ShortcutListReadingUtils::getProbabilityFromFlags(shortcutFlags); - shortcuts.push_back( - WordProperty::ShortcutProperty(&shortcutTarget, shortcutProbability)); + shortcuts.emplace_back(&shortcutTarget, shortcutProbability); } } return WordProperty(&codePointVector, ptNodeParams.isNotAWord(), diff --git a/native/jni/src/suggest/policyimpl/dictionary/structure/v4/ver4_patricia_trie_policy.cpp b/native/jni/src/suggest/policyimpl/dictionary/structure/v4/ver4_patricia_trie_policy.cpp index 1a38a27ff..107ddab2c 100644 --- a/native/jni/src/suggest/policyimpl/dictionary/structure/v4/ver4_patricia_trie_policy.cpp +++ b/native/jni/src/suggest/policyimpl/dictionary/structure/v4/ver4_patricia_trie_policy.cpp @@ -382,16 +382,16 @@ const WordProperty Ver4PatriciaTriePolicy::getWordProperty(const int *const code const int codePointCount = getCodePointsAndProbabilityAndReturnCodePointCount( word1TerminalPtNodePos, MAX_WORD_LENGTH, bigramWord1CodePoints, &word1Probability); - std::vector<int> word1(bigramWord1CodePoints, + const std::vector<int> word1(bigramWord1CodePoints, bigramWord1CodePoints + codePointCount); const HistoricalInfo *const historicalInfo = bigramEntry.getHistoricalInfo(); const int probability = bigramEntry.hasHistoricalInfo() ? ForgettingCurveUtils::decodeProbability( bigramEntry.getHistoricalInfo(), mHeaderPolicy) : - bigramEntry.getProbability(); - bigrams.push_back(WordProperty::BigramProperty(&word1, probability, + getProbability(word1Probability, bigramEntry.getProbability()); + bigrams.emplace_back(&word1, probability, historicalInfo->getTimeStamp(), historicalInfo->getLevel(), - historicalInfo->getCount())); + historicalInfo->getCount()); } } // Fetch shortcut information. @@ -407,8 +407,8 @@ const WordProperty Ver4PatriciaTriePolicy::getWordProperty(const int *const code int shortcutProbability = NOT_A_PROBABILITY; shortcutDictContent->getShortcutEntryAndAdvancePosition(MAX_WORD_LENGTH, shortcutTarget, &shortcutTargetLength, &shortcutProbability, &hasNext, &shortcutPos); - std::vector<int> target(shortcutTarget, shortcutTarget + shortcutTargetLength); - shortcuts.push_back(WordProperty::ShortcutProperty(&target, shortcutProbability)); + const std::vector<int> target(shortcutTarget, shortcutTarget + shortcutTargetLength); + shortcuts.emplace_back(&target, shortcutProbability); } } return WordProperty(&codePointVector, ptNodeParams.isNotAWord(), diff --git a/tests/src/com/android/inputmethod/keyboard/layout/Qwerty.java b/tests/src/com/android/inputmethod/keyboard/layout/Qwerty.java index 8b35e3f80..325b78450 100644 --- a/tests/src/com/android/inputmethod/keyboard/layout/Qwerty.java +++ b/tests/src/com/android/inputmethod/keyboard/layout/Qwerty.java @@ -24,8 +24,10 @@ import com.android.inputmethod.keyboard.layout.expected.LayoutBase; * The QWERTY alphabet keyboard. */ public final class Qwerty extends LayoutBase { + public static final String LAYOUT_NAME = "qwerty"; + public static ExpectedKey[][] getLayout(final boolean isPhone) { - return toCommonAlphabet(ALPHABET_COMMON, isPhone); + return getDefaultAlphabetLayout(ALPHABET_COMMON, isPhone); } private static final ExpectedKey[][] ALPHABET_COMMON = new ExpectedKeyboardBuilder(10, 9, 7, 3) diff --git a/tests/src/com/android/inputmethod/keyboard/layout/Symbols.java b/tests/src/com/android/inputmethod/keyboard/layout/Symbols.java index bf46d5d0d..6fcfa0520 100644 --- a/tests/src/com/android/inputmethod/keyboard/layout/Symbols.java +++ b/tests/src/com/android/inputmethod/keyboard/layout/Symbols.java @@ -30,14 +30,13 @@ public final class Symbols extends LayoutBase { } public static ExpectedKey[][] getDefaultLayout(final boolean isPhone) { - final ExpectedKeyboardBuilder builder = new ExpectedKeyboardBuilder(SYMBOLS_COMMON); + final ExpectedKeyboardBuilder builder = new ExpectedKeyboardBuilder(getLayout(isPhone)); builder.replaceKeyOfLabel(CURRENCY, Symbols.CURRENCY_DOLLAR); builder.replaceKeyOfLabel(DOUBLE_QUOTE, key("\"", join(Symbols.DOUBLE_QUOTES_9LR, Symbols.DOUBLE_ANGLE_QUOTES_LR))); builder.replaceKeyOfLabel(SINGLE_QUOTE, key("'", join(Symbols.SINGLE_QUOTES_9LR, Symbols.SINGLE_ANGLE_QUOTES_LR))); - final ExpectedKey[][] symbolsCommon = builder.build(); - return isPhone ? toPhoneSymbol(symbolsCommon) : toTabletSymbols(symbolsCommon); + return builder.build(); } // Functional keys. diff --git a/tests/src/com/android/inputmethod/keyboard/layout/SymbolsShifted.java b/tests/src/com/android/inputmethod/keyboard/layout/SymbolsShifted.java index d04ebf021..4d9ae4348 100644 --- a/tests/src/com/android/inputmethod/keyboard/layout/SymbolsShifted.java +++ b/tests/src/com/android/inputmethod/keyboard/layout/SymbolsShifted.java @@ -31,11 +31,9 @@ public final class SymbolsShifted extends LayoutBase { } public static ExpectedKey[][] getDefaultLayout(final boolean isPhone) { - final ExpectedKeyboardBuilder builder = new ExpectedKeyboardBuilder(SYMBOLS_SHIFTED_COMMON); + final ExpectedKeyboardBuilder builder = new ExpectedKeyboardBuilder(getLayout(isPhone)); builder.replaceKeyOfLabel(OTHER_CURRENCIES, SymbolsShifted.CURRENCIES_OTHER_THAN_DOLLAR); - final ExpectedKey[][] symbolsShiftedCommon = builder.build(); - return isPhone ? toPhoneSymbolsShifted(symbolsShiftedCommon) - : toTabletSymbolsShifted(symbolsShiftedCommon); + return builder.build(); } // Functional key. diff --git a/tests/src/com/android/inputmethod/keyboard/layout/expected/LayoutBase.java b/tests/src/com/android/inputmethod/keyboard/layout/expected/LayoutBase.java index 329f70471..813a51f74 100644 --- a/tests/src/com/android/inputmethod/keyboard/layout/expected/LayoutBase.java +++ b/tests/src/com/android/inputmethod/keyboard/layout/expected/LayoutBase.java @@ -121,9 +121,10 @@ public class LayoutBase { "&", "%", "+", "\"", "-", ":", "@" }; + // Helper method to create alphabet layout for phone by adding special function keys except + // shift key. private static ExpectedKeyboardBuilder toPhoneAlphabet(final ExpectedKeyboardBuilder builder) { return builder - .addKeysOnTheLeftOfRow(3, key(SHIFT_KEY, CAPSLOCK_MORE_KEY)) .addKeysOnTheRightOfRow(3, DELETE_KEY) .setLabelsOfRow(4, ",", " ", ".") .setMoreKeysOf(",", SETTINGS_KEY) @@ -134,8 +135,7 @@ public class LayoutBase { // Helper method to create alphabet layout for tablet by adding special function keys except // shift key. - public static ExpectedKeyboardBuilder toTabletAlphabetWithoutShiftKeys( - final ExpectedKeyboardBuilder builder) { + private static ExpectedKeyboardBuilder toTabletAlphabet(final ExpectedKeyboardBuilder builder) { return builder // U+00BF: "¿" INVERTED QUESTION MARK // U+00A1: "¡" INVERTED EXCLAMATION MARK @@ -150,13 +150,25 @@ public class LayoutBase { } // Helper method to create alphabet layout by adding special function keys. - public static ExpectedKey[][] toCommonAlphabet(final ExpectedKey[][] common, + public static ExpectedKey[][] getAlphabetLayoutWithoutShiftKeys(final ExpectedKey[][] common, final boolean isPhone) { final ExpectedKeyboardBuilder builder = new ExpectedKeyboardBuilder(common); if (isPhone) { toPhoneAlphabet(builder); } else { - toTabletAlphabetWithoutShiftKeys(builder); + toTabletAlphabet(builder).build(); + } + return builder.build(); + } + + // Helper method to create alphabet layout by adding special function keys. + public static ExpectedKey[][] getDefaultAlphabetLayout(final ExpectedKey[][] common, + final boolean isPhone) { + final ExpectedKeyboardBuilder builder = new ExpectedKeyboardBuilder( + getAlphabetLayoutWithoutShiftKeys(common, isPhone)); + if (isPhone) { + builder.addKeysOnTheLeftOfRow(3, key(SHIFT_KEY, CAPSLOCK_MORE_KEY)); + } else { builder.addKeysOnTheLeftOfRow(3, key(SHIFT_KEY, CAPSLOCK_MORE_KEY)) .addKeysOnTheRightOfRow(3, key(SHIFT_KEY, CAPSLOCK_MORE_KEY)); } diff --git a/tests/src/com/android/inputmethod/keyboard/layout/tests/TestsEnglishUS.java b/tests/src/com/android/inputmethod/keyboard/layout/tests/TestsEnglishUS.java index e160ae84f..fd1a60619 100644 --- a/tests/src/com/android/inputmethod/keyboard/layout/tests/TestsEnglishUS.java +++ b/tests/src/com/android/inputmethod/keyboard/layout/tests/TestsEnglishUS.java @@ -36,7 +36,7 @@ public final class TestsEnglishUS extends LayoutTestsBase { @Override String getTestKeyboardLayout() { - return "qwerty"; + return Qwerty.LAYOUT_NAME; } @Override |