Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a2b129e9 authored by Satoshi Kataoka's avatar Satoshi Kataoka Committed by Android Git Automerger
Browse files

am 0b0d9827: am 95fe8267: Move suggest logic to AOSP

* commit '0b0d9827':
  Move suggest logic to AOSP
parents d9f35e32 0b0d9827
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -29,9 +29,8 @@ 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/dicnode \
    $(LATIN_IME_SRC_FULLPATH_DIR)/suggest/core/policy \
    $(LATIN_IME_SRC_FULLPATH_DIR)/suggest/core/session \
    $(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_CFLAGS += -Werror -Wall -Wextra -Weffc++ -Wformat=2 -Wcast-qual -Wcast-align \
@@ -70,8 +69,10 @@ LATIN_IME_CORE_SRC_FILES := \
    suggest/core/dicnode/dic_node_utils.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 \
+65 −0
Original line number Diff line number Diff line
/*
 * 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_SHORTCUT_UTILS
#define LATINIME_SHORTCUT_UTILS

#include "defines.h"
#include "dic_node_utils.h"
#include "terminal_attributes.h"

namespace latinime {

class ShortcutUtils {
 public:
    static int outputShortcuts(const TerminalAttributes *const terminalAttributes,
            int outputWordIndex, const int finalScore, int *const outputCodePoints,
            int *const frequencies, int *const outputTypes, const bool sameAsTyped) {
        TerminalAttributes::ShortcutIterator iterator = terminalAttributes->getShortcutIterator();
        while (iterator.hasNextShortcutTarget() && outputWordIndex < MAX_RESULTS) {
            int shortcutTarget[MAX_WORD_LENGTH];
            int shortcutProbability;
            const int shortcutTargetStringLength = iterator.getNextShortcutTarget(
                    MAX_WORD_LENGTH, shortcutTarget, &shortcutProbability);
            int shortcutScore;
            int kind;
            if (shortcutProbability == BinaryFormat::WHITELIST_SHORTCUT_PROBABILITY
                    && sameAsTyped) {
                shortcutScore = S_INT_MAX;
                kind = Dictionary::KIND_WHITELIST;
            } else {
                // shortcut entry's score == its base entry's score - 1
                shortcutScore = finalScore;
                // Protection against int underflow
                shortcutScore = max(S_INT_MIN + 1, shortcutScore) - 1;
                kind = Dictionary::KIND_CORRECTION;
            }
            outputTypes[outputWordIndex] = kind;
            frequencies[outputWordIndex] = shortcutScore;
            frequencies[outputWordIndex] = max(S_INT_MIN + 1, shortcutScore) - 1;
            const int startIndex2 = outputWordIndex * MAX_WORD_LENGTH;
            DicNodeUtils::appendTwoWords(0, 0, shortcutTarget, shortcutTargetStringLength,
                    &outputCodePoints[startIndex2]);
            ++outputWordIndex;
        }
        return outputWordIndex;
    }

 private:
    DISALLOW_IMPLICIT_CONSTRUCTORS(ShortcutUtils);
};
} // namespace latinime
#endif // LATINIME_SHORTCUT_UTILS
Loading