suggest.h revision a000a32c8094d0dec453b0cebf748a089b0ad39a
1/* 2 * Copyright (C) 2012 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17#ifndef LATINIME_SUGGEST_IMPL_H 18#define LATINIME_SUGGEST_IMPL_H 19 20#include "defines.h" 21#include "suggest/core/suggest_interface.h" 22#include "suggest/core/policy/suggest_policy.h" 23 24namespace latinime { 25 26// Naming convention 27// - Distance: "Weighted" edit distance -- used both for spatial and language. 28// - Compound Distance: Spatial Distance + Language Distance -- used for pruning and scoring 29// - Cost: delta/diff for Distance -- used both for spatial and language 30// - Length: "Non-weighted" -- used only for spatial 31// - Probability: "Non-weighted" -- used only for language 32// - Score: Final calibrated score based on the compound distance, which is sent to java as the 33// priority of a suggested word 34 35class DicNode; 36class DicTraverseSession; 37class ProximityInfo; 38class Scoring; 39class Traversal; 40class Weighting; 41 42class Suggest : public SuggestInterface { 43 public: 44 AK_FORCE_INLINE Suggest(const SuggestPolicy *const suggestPolicy) 45 : TRAVERSAL(suggestPolicy ? suggestPolicy->getTraversal() : 0), 46 SCORING(suggestPolicy ? suggestPolicy->getScoring() : 0), 47 WEIGHTING(suggestPolicy ? suggestPolicy->getWeighting() : 0) {} 48 AK_FORCE_INLINE virtual ~Suggest() {} 49 int getSuggestions(ProximityInfo *pInfo, void *traverseSession, int *inputXs, int *inputYs, 50 int *times, int *pointerIds, int *inputCodePoints, int inputSize, int commitPoint, 51 int *outWords, int *outputScores, int *outputIndices, int *outputTypes, 52 int *outputAutoCommitFirstWordConfidence) const; 53 54 private: 55 DISALLOW_IMPLICIT_CONSTRUCTORS(Suggest); 56 void createNextWordDicNode(DicTraverseSession *traverseSession, DicNode *dicNode, 57 const bool spaceSubstitution) const; 58 void initializeSearch(DicTraverseSession *traverseSession, int commitPoint) const; 59 void expandCurrentDicNodes(DicTraverseSession *traverseSession) const; 60 void processTerminalDicNode(DicTraverseSession *traverseSession, DicNode *dicNode) const; 61 void processExpandedDicNode(DicTraverseSession *traverseSession, DicNode *dicNode) const; 62 void weightChildNode(DicTraverseSession *traverseSession, DicNode *dicNode) const; 63 void processDicNodeAsOmission(DicTraverseSession *traverseSession, DicNode *dicNode) const; 64 void processDicNodeAsDigraph(DicTraverseSession *traverseSession, DicNode *dicNode) const; 65 void processDicNodeAsTransposition(DicTraverseSession *traverseSession, 66 DicNode *dicNode) const; 67 void processDicNodeAsInsertion(DicTraverseSession *traverseSession, DicNode *dicNode) const; 68 void processDicNodeAsAdditionalProximityChar(DicTraverseSession *traverseSession, 69 DicNode *dicNode, DicNode *childDicNode) const; 70 void processDicNodeAsSubstitution(DicTraverseSession *traverseSession, DicNode *dicNode, 71 DicNode *childDicNode) const; 72 void processDicNodeAsMatch(DicTraverseSession *traverseSession, 73 DicNode *childDicNode) const; 74 75 static const int MIN_CONTINUOUS_SUGGESTION_INPUT_SIZE; 76 77 const Traversal *const TRAVERSAL; 78 const Scoring *const SCORING; 79 const Weighting *const WEIGHTING; 80}; 81} // namespace latinime 82#endif // LATINIME_SUGGEST_IMPL_H 83