dic_traverse_session.cpp revision d81654cd61bd10f7cb56bfa4c89b34e9cfb18598
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" 21bd0d1afdb28a28e2ddac1409208c59ba64350399Keisuke Kuroynagi#include "suggest/core/dictionary/binary_dictionary_header.h" 22a65c267b1f1207e54c6f821148c600e3899b7f9cKen Wakasa#include "suggest/core/dictionary/dictionary.h" 23d81654cd61bd10f7cb56bfa4c89b34e9cfb18598Keisuke Kuroyanagi#include "suggest/core/policy/dictionary_structure_with_buffer_policy.h" 243107b467c91c471ce4e00c5d8de559f7b0da2cd6Satoshi Kataoka 253107b467c91c471ce4e00c5d8de559f7b0da2cd6Satoshi Kataokanamespace latinime { 263107b467c91c471ce4e00c5d8de559f7b0da2cd6Satoshi Kataoka 273107b467c91c471ce4e00c5d8de559f7b0da2cd6Satoshi Kataokavoid DicTraverseSession::init(const Dictionary *const dictionary, const int *prevWord, 28338ef65077f43d6a35665a5c8eb6a44928332547Keisuke Kuroyanagi int prevWordLength, const SuggestOptions *const suggestOptions) { 293107b467c91c471ce4e00c5d8de559f7b0da2cd6Satoshi Kataoka mDictionary = dictionary; 30d81654cd61bd10f7cb56bfa4c89b34e9cfb18598Keisuke Kuroyanagi mMultiWordCostMultiplier = getDictionaryStructurePolicy()->getHeader() 31d81654cd61bd10f7cb56bfa4c89b34e9cfb18598Keisuke Kuroyanagi ->getMultiWordCostMultiplier(); 32338ef65077f43d6a35665a5c8eb6a44928332547Keisuke Kuroyanagi mSuggestOptions = suggestOptions; 333107b467c91c471ce4e00c5d8de559f7b0da2cd6Satoshi Kataoka if (!prevWord) { 348a7129530b4dbb2453e88747f251d30a2ce75a45Keisuke Kuroynagi mPrevWordPos = NOT_A_VALID_WORD_POS; 353107b467c91c471ce4e00c5d8de559f7b0da2cd6Satoshi Kataoka return; 363107b467c91c471ce4e00c5d8de559f7b0da2cd6Satoshi Kataoka } 375fa33a701d4b8405254d3369c714702481a90e6bTom Ouyang // TODO: merge following similar calls to getTerminalPosition into one case-insensitive call. 38d81654cd61bd10f7cb56bfa4c89b34e9cfb18598Keisuke Kuroyanagi mPrevWordPos = getDictionaryStructurePolicy()->getTerminalNodePositionOfWord( 39e1ebef6124241ef51d5ed17884e6299a330d496bKeisuke Kuroyanagi prevWord, prevWordLength, false /* forceLowerCaseSearch */); 408a7129530b4dbb2453e88747f251d30a2ce75a45Keisuke Kuroynagi if (mPrevWordPos == NOT_A_VALID_WORD_POS) { 415fa33a701d4b8405254d3369c714702481a90e6bTom Ouyang // Check bigrams for lower-cased previous word if original was not found. Useful for 425fa33a701d4b8405254d3369c714702481a90e6bTom Ouyang // auto-capitalized words like "The [current_word]". 43d81654cd61bd10f7cb56bfa4c89b34e9cfb18598Keisuke Kuroyanagi mPrevWordPos = getDictionaryStructurePolicy()->getTerminalNodePositionOfWord( 44e1ebef6124241ef51d5ed17884e6299a330d496bKeisuke Kuroyanagi prevWord, prevWordLength, true /* forceLowerCaseSearch */); 455fa33a701d4b8405254d3369c714702481a90e6bTom Ouyang } 463107b467c91c471ce4e00c5d8de559f7b0da2cd6Satoshi Kataoka} 473107b467c91c471ce4e00c5d8de559f7b0da2cd6Satoshi Kataoka 483107b467c91c471ce4e00c5d8de559f7b0da2cd6Satoshi Kataokavoid DicTraverseSession::setupForGetSuggestions(const ProximityInfo *pInfo, 493107b467c91c471ce4e00c5d8de559f7b0da2cd6Satoshi Kataoka const int *inputCodePoints, const int inputSize, const int *const inputXs, 503107b467c91c471ce4e00c5d8de559f7b0da2cd6Satoshi Kataoka const int *const inputYs, const int *const times, const int *const pointerIds, 513107b467c91c471ce4e00c5d8de559f7b0da2cd6Satoshi Kataoka const float maxSpatialDistance, const int maxPointerCount) { 523107b467c91c471ce4e00c5d8de559f7b0da2cd6Satoshi Kataoka mProximityInfo = pInfo; 533107b467c91c471ce4e00c5d8de559f7b0da2cd6Satoshi Kataoka mMaxPointerCount = maxPointerCount; 543107b467c91c471ce4e00c5d8de559f7b0da2cd6Satoshi Kataoka initializeProximityInfoStates(inputCodePoints, inputXs, inputYs, times, pointerIds, inputSize, 553107b467c91c471ce4e00c5d8de559f7b0da2cd6Satoshi Kataoka maxSpatialDistance, maxPointerCount); 563107b467c91c471ce4e00c5d8de559f7b0da2cd6Satoshi Kataoka} 573107b467c91c471ce4e00c5d8de559f7b0da2cd6Satoshi Kataoka 58d81654cd61bd10f7cb56bfa4c89b34e9cfb18598Keisuke Kuroyanagiconst DictionaryStructureWithBufferPolicy *DicTraverseSession::getDictionaryStructurePolicy() 59d81654cd61bd10f7cb56bfa4c89b34e9cfb18598Keisuke Kuroyanagi const { 60d81654cd61bd10f7cb56bfa4c89b34e9cfb18598Keisuke Kuroyanagi return mDictionary->getDictionaryStructurePolicy(); 613107b467c91c471ce4e00c5d8de559f7b0da2cd6Satoshi Kataoka} 623107b467c91c471ce4e00c5d8de559f7b0da2cd6Satoshi Kataoka 633107b467c91c471ce4e00c5d8de559f7b0da2cd6Satoshi Kataokavoid DicTraverseSession::resetCache(const int nextActiveCacheSize, const int maxWords) { 643107b467c91c471ce4e00c5d8de559f7b0da2cd6Satoshi Kataoka mDicNodesCache.reset(nextActiveCacheSize, maxWords); 659559dd2e30de288a9ff7069bfc59f8500b949a88Tom Ouyang mMultiBigramMap.clear(); 663107b467c91c471ce4e00c5d8de559f7b0da2cd6Satoshi Kataoka mPartiallyCommited = false; 673107b467c91c471ce4e00c5d8de559f7b0da2cd6Satoshi Kataoka} 683107b467c91c471ce4e00c5d8de559f7b0da2cd6Satoshi Kataoka 693107b467c91c471ce4e00c5d8de559f7b0da2cd6Satoshi Kataokavoid DicTraverseSession::initializeProximityInfoStates(const int *const inputCodePoints, 703107b467c91c471ce4e00c5d8de559f7b0da2cd6Satoshi Kataoka const int *const inputXs, const int *const inputYs, const int *const times, 713107b467c91c471ce4e00c5d8de559f7b0da2cd6Satoshi Kataoka const int *const pointerIds, const int inputSize, const float maxSpatialDistance, 723107b467c91c471ce4e00c5d8de559f7b0da2cd6Satoshi Kataoka const int maxPointerCount) { 733107b467c91c471ce4e00c5d8de559f7b0da2cd6Satoshi Kataoka ASSERT(1 <= maxPointerCount && maxPointerCount <= MAX_POINTER_COUNT_G); 743107b467c91c471ce4e00c5d8de559f7b0da2cd6Satoshi Kataoka mInputSize = 0; 753107b467c91c471ce4e00c5d8de559f7b0da2cd6Satoshi Kataoka for (int i = 0; i < maxPointerCount; ++i) { 763107b467c91c471ce4e00c5d8de559f7b0da2cd6Satoshi Kataoka mProximityInfoStates[i].initInputParams(i, maxSpatialDistance, getProximityInfo(), 773107b467c91c471ce4e00c5d8de559f7b0da2cd6Satoshi Kataoka inputCodePoints, inputSize, inputXs, inputYs, times, pointerIds, 783107b467c91c471ce4e00c5d8de559f7b0da2cd6Satoshi Kataoka maxPointerCount == MAX_POINTER_COUNT_G 793107b467c91c471ce4e00c5d8de559f7b0da2cd6Satoshi Kataoka /* TODO: this is a hack. fix proximity info state */); 803107b467c91c471ce4e00c5d8de559f7b0da2cd6Satoshi Kataoka mInputSize += mProximityInfoStates[i].size(); 813107b467c91c471ce4e00c5d8de559f7b0da2cd6Satoshi Kataoka } 823107b467c91c471ce4e00c5d8de559f7b0da2cd6Satoshi Kataoka} 833107b467c91c471ce4e00c5d8de559f7b0da2cd6Satoshi Kataoka} // namespace latinime 84