dic_traverse_session.cpp revision bd0d1afdb28a28e2ddac1409208c59ba64350399
13107b467c91c471ce4e00c5d8de559f7b0da2cd6Satoshi Kataoka/* 23107b467c91c471ce4e00c5d8de559f7b0da2cd6Satoshi Kataoka * Copyright (C) 2012 The Android Open Source Project 33107b467c91c471ce4e00c5d8de559f7b0da2cd6Satoshi Kataoka * 43107b467c91c471ce4e00c5d8de559f7b0da2cd6Satoshi Kataoka * Licensed under the Apache License, Version 2.0 (the "License"); 53107b467c91c471ce4e00c5d8de559f7b0da2cd6Satoshi Kataoka * you may not use this file except in compliance with the License. 63107b467c91c471ce4e00c5d8de559f7b0da2cd6Satoshi Kataoka * You may obtain a copy of the License at 73107b467c91c471ce4e00c5d8de559f7b0da2cd6Satoshi Kataoka * 83107b467c91c471ce4e00c5d8de559f7b0da2cd6Satoshi Kataoka * http://www.apache.org/licenses/LICENSE-2.0 93107b467c91c471ce4e00c5d8de559f7b0da2cd6Satoshi Kataoka * 103107b467c91c471ce4e00c5d8de559f7b0da2cd6Satoshi Kataoka * Unless required by applicable law or agreed to in writing, software 113107b467c91c471ce4e00c5d8de559f7b0da2cd6Satoshi Kataoka * distributed under the License is distributed on an "AS IS" BASIS, 123107b467c91c471ce4e00c5d8de559f7b0da2cd6Satoshi Kataoka * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 133107b467c91c471ce4e00c5d8de559f7b0da2cd6Satoshi Kataoka * See the License for the specific language governing permissions and 143107b467c91c471ce4e00c5d8de559f7b0da2cd6Satoshi Kataoka * limitations under the License. 153107b467c91c471ce4e00c5d8de559f7b0da2cd6Satoshi Kataoka */ 163107b467c91c471ce4e00c5d8de559f7b0da2cd6Satoshi Kataoka 17b68e73448104714e8f12f89a1e00fb10b5fd14c4Ken Wakasa#include "suggest/core/session/dic_traverse_session.h" 18b68e73448104714e8f12f89a1e00fb10b5fd14c4Ken Wakasa 193107b467c91c471ce4e00c5d8de559f7b0da2cd6Satoshi Kataoka#include "defines.h" 203107b467c91c471ce4e00c5d8de559f7b0da2cd6Satoshi Kataoka#include "jni.h" 21b68e73448104714e8f12f89a1e00fb10b5fd14c4Ken Wakasa#include "suggest/core/dicnode/dic_node_utils.h" 22bd0d1afdb28a28e2ddac1409208c59ba64350399Keisuke Kuroynagi#include "suggest/core/dictionary/binary_dictionary_header.h" 230ecfb9424754341d7ee41557fc1f913cb6ca79c2Keisuke Kuroyanagi#include "suggest/core/dictionary/binary_dictionary_info.h" 24a65c267b1f1207e54c6f821148c600e3899b7f9cKen Wakasa#include "suggest/core/dictionary/binary_format.h" 25a65c267b1f1207e54c6f821148c600e3899b7f9cKen Wakasa#include "suggest/core/dictionary/dictionary.h" 263107b467c91c471ce4e00c5d8de559f7b0da2cd6Satoshi Kataoka 273107b467c91c471ce4e00c5d8de559f7b0da2cd6Satoshi Kataokanamespace latinime { 283107b467c91c471ce4e00c5d8de559f7b0da2cd6Satoshi Kataoka 293107b467c91c471ce4e00c5d8de559f7b0da2cd6Satoshi Kataokavoid DicTraverseSession::init(const Dictionary *const dictionary, const int *prevWord, 30338ef65077f43d6a35665a5c8eb6a44928332547Keisuke Kuroyanagi int prevWordLength, const SuggestOptions *const suggestOptions) { 313107b467c91c471ce4e00c5d8de559f7b0da2cd6Satoshi Kataoka mDictionary = dictionary; 32bd0d1afdb28a28e2ddac1409208c59ba64350399Keisuke Kuroynagi mMultiWordCostMultiplier = mDictionary->getBinaryDictionaryInfo() 33bd0d1afdb28a28e2ddac1409208c59ba64350399Keisuke Kuroynagi ->getHeader()->getMultiWordCostMultiplier(); 34338ef65077f43d6a35665a5c8eb6a44928332547Keisuke Kuroyanagi mSuggestOptions = suggestOptions; 353107b467c91c471ce4e00c5d8de559f7b0da2cd6Satoshi Kataoka if (!prevWord) { 363107b467c91c471ce4e00c5d8de559f7b0da2cd6Satoshi Kataoka mPrevWordPos = NOT_VALID_WORD; 373107b467c91c471ce4e00c5d8de559f7b0da2cd6Satoshi Kataoka return; 383107b467c91c471ce4e00c5d8de559f7b0da2cd6Satoshi Kataoka } 395fa33a701d4b8405254d3369c714702481a90e6bTom Ouyang // TODO: merge following similar calls to getTerminalPosition into one case-insensitive call. 400ecfb9424754341d7ee41557fc1f913cb6ca79c2Keisuke Kuroyanagi mPrevWordPos = BinaryFormat::getTerminalPosition( 410ecfb9424754341d7ee41557fc1f913cb6ca79c2Keisuke Kuroyanagi dictionary->getBinaryDictionaryInfo()->getDictRoot(), prevWord, 425fa33a701d4b8405254d3369c714702481a90e6bTom Ouyang prevWordLength, false /* forceLowerCaseSearch */); 435fa33a701d4b8405254d3369c714702481a90e6bTom Ouyang if (mPrevWordPos == NOT_VALID_WORD) { 445fa33a701d4b8405254d3369c714702481a90e6bTom Ouyang // Check bigrams for lower-cased previous word if original was not found. Useful for 455fa33a701d4b8405254d3369c714702481a90e6bTom Ouyang // auto-capitalized words like "The [current_word]". 460ecfb9424754341d7ee41557fc1f913cb6ca79c2Keisuke Kuroyanagi mPrevWordPos = BinaryFormat::getTerminalPosition( 470ecfb9424754341d7ee41557fc1f913cb6ca79c2Keisuke Kuroyanagi dictionary->getBinaryDictionaryInfo()->getDictRoot(), prevWord, 485fa33a701d4b8405254d3369c714702481a90e6bTom Ouyang prevWordLength, true /* forceLowerCaseSearch */); 495fa33a701d4b8405254d3369c714702481a90e6bTom Ouyang } 503107b467c91c471ce4e00c5d8de559f7b0da2cd6Satoshi Kataoka} 513107b467c91c471ce4e00c5d8de559f7b0da2cd6Satoshi Kataoka 523107b467c91c471ce4e00c5d8de559f7b0da2cd6Satoshi Kataokavoid DicTraverseSession::setupForGetSuggestions(const ProximityInfo *pInfo, 533107b467c91c471ce4e00c5d8de559f7b0da2cd6Satoshi Kataoka const int *inputCodePoints, const int inputSize, const int *const inputXs, 543107b467c91c471ce4e00c5d8de559f7b0da2cd6Satoshi Kataoka const int *const inputYs, const int *const times, const int *const pointerIds, 553107b467c91c471ce4e00c5d8de559f7b0da2cd6Satoshi Kataoka const float maxSpatialDistance, const int maxPointerCount) { 563107b467c91c471ce4e00c5d8de559f7b0da2cd6Satoshi Kataoka mProximityInfo = pInfo; 573107b467c91c471ce4e00c5d8de559f7b0da2cd6Satoshi Kataoka mMaxPointerCount = maxPointerCount; 583107b467c91c471ce4e00c5d8de559f7b0da2cd6Satoshi Kataoka initializeProximityInfoStates(inputCodePoints, inputXs, inputYs, times, pointerIds, inputSize, 593107b467c91c471ce4e00c5d8de559f7b0da2cd6Satoshi Kataoka maxSpatialDistance, maxPointerCount); 603107b467c91c471ce4e00c5d8de559f7b0da2cd6Satoshi Kataoka} 613107b467c91c471ce4e00c5d8de559f7b0da2cd6Satoshi Kataoka 620ecfb9424754341d7ee41557fc1f913cb6ca79c2Keisuke Kuroyanagiconst BinaryDictionaryInfo *DicTraverseSession::getBinaryDictionaryInfo() const { 630ecfb9424754341d7ee41557fc1f913cb6ca79c2Keisuke Kuroyanagi return mDictionary->getBinaryDictionaryInfo(); 643107b467c91c471ce4e00c5d8de559f7b0da2cd6Satoshi Kataoka} 653107b467c91c471ce4e00c5d8de559f7b0da2cd6Satoshi Kataoka 663107b467c91c471ce4e00c5d8de559f7b0da2cd6Satoshi Kataokavoid DicTraverseSession::resetCache(const int nextActiveCacheSize, const int maxWords) { 673107b467c91c471ce4e00c5d8de559f7b0da2cd6Satoshi Kataoka mDicNodesCache.reset(nextActiveCacheSize, maxWords); 689559dd2e30de288a9ff7069bfc59f8500b949a88Tom Ouyang mMultiBigramMap.clear(); 693107b467c91c471ce4e00c5d8de559f7b0da2cd6Satoshi Kataoka mPartiallyCommited = false; 703107b467c91c471ce4e00c5d8de559f7b0da2cd6Satoshi Kataoka} 713107b467c91c471ce4e00c5d8de559f7b0da2cd6Satoshi Kataoka 723107b467c91c471ce4e00c5d8de559f7b0da2cd6Satoshi Kataokavoid DicTraverseSession::initializeProximityInfoStates(const int *const inputCodePoints, 733107b467c91c471ce4e00c5d8de559f7b0da2cd6Satoshi Kataoka const int *const inputXs, const int *const inputYs, const int *const times, 743107b467c91c471ce4e00c5d8de559f7b0da2cd6Satoshi Kataoka const int *const pointerIds, const int inputSize, const float maxSpatialDistance, 753107b467c91c471ce4e00c5d8de559f7b0da2cd6Satoshi Kataoka const int maxPointerCount) { 763107b467c91c471ce4e00c5d8de559f7b0da2cd6Satoshi Kataoka ASSERT(1 <= maxPointerCount && maxPointerCount <= MAX_POINTER_COUNT_G); 773107b467c91c471ce4e00c5d8de559f7b0da2cd6Satoshi Kataoka mInputSize = 0; 783107b467c91c471ce4e00c5d8de559f7b0da2cd6Satoshi Kataoka for (int i = 0; i < maxPointerCount; ++i) { 793107b467c91c471ce4e00c5d8de559f7b0da2cd6Satoshi Kataoka mProximityInfoStates[i].initInputParams(i, maxSpatialDistance, getProximityInfo(), 803107b467c91c471ce4e00c5d8de559f7b0da2cd6Satoshi Kataoka inputCodePoints, inputSize, inputXs, inputYs, times, pointerIds, 813107b467c91c471ce4e00c5d8de559f7b0da2cd6Satoshi Kataoka maxPointerCount == MAX_POINTER_COUNT_G 823107b467c91c471ce4e00c5d8de559f7b0da2cd6Satoshi Kataoka /* TODO: this is a hack. fix proximity info state */); 833107b467c91c471ce4e00c5d8de559f7b0da2cd6Satoshi Kataoka mInputSize += mProximityInfoStates[i].size(); 843107b467c91c471ce4e00c5d8de559f7b0da2cd6Satoshi Kataoka } 853107b467c91c471ce4e00c5d8de559f7b0da2cd6Satoshi Kataoka} 863107b467c91c471ce4e00c5d8de559f7b0da2cd6Satoshi Kataoka} // namespace latinime 87