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 24 namespace 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 35 class DicNode; 36 class DicTraverseSession; 37 class ProximityInfo; 38 class Scoring; 39 class SuggestionResults; 40 class Traversal; 41 class Weighting; 42 43 class Suggest : public SuggestInterface { 44 public: 45 AK_FORCE_INLINE Suggest(const SuggestPolicy *const suggestPolicy) 46 : TRAVERSAL(suggestPolicy ? suggestPolicy->getTraversal() : nullptr), 47 SCORING(suggestPolicy ? suggestPolicy->getScoring() : nullptr), 48 WEIGHTING(suggestPolicy ? suggestPolicy->getWeighting() : nullptr) {} 49 AK_FORCE_INLINE virtual ~Suggest() {} 50 void getSuggestions(ProximityInfo *pInfo, void *traverseSession, int *inputXs, int *inputYs, 51 int *times, int *pointerIds, int *inputCodePoints, int inputSize, 52 const float weightOfLangModelVsSpatialModel, 53 SuggestionResults *const outSuggestionResults) const; 54 55 private: 56 DISALLOW_IMPLICIT_CONSTRUCTORS(Suggest); 57 void createNextWordDicNode(DicTraverseSession *traverseSession, DicNode *dicNode, 58 const bool spaceSubstitution) const; 59 void initializeSearch(DicTraverseSession *traverseSession) const; 60 void expandCurrentDicNodes(DicTraverseSession *traverseSession) const; 61 void processTerminalDicNode(DicTraverseSession *traverseSession, DicNode *dicNode) const; 62 void processExpandedDicNode(DicTraverseSession *traverseSession, DicNode *dicNode) const; 63 void weightChildNode(DicTraverseSession *traverseSession, DicNode *dicNode) const; 64 void processDicNodeAsOmission(DicTraverseSession *traverseSession, DicNode *dicNode) const; 65 void processDicNodeAsDigraph(DicTraverseSession *traverseSession, DicNode *dicNode) const; 66 void processDicNodeAsTransposition(DicTraverseSession *traverseSession, 67 DicNode *dicNode) const; 68 void processDicNodeAsInsertion(DicTraverseSession *traverseSession, DicNode *dicNode) const; 69 void processDicNodeAsAdditionalProximityChar(DicTraverseSession *traverseSession, 70 DicNode *dicNode, DicNode *childDicNode) const; 71 void processDicNodeAsSubstitution(DicTraverseSession *traverseSession, DicNode *dicNode, 72 DicNode *childDicNode) const; 73 void processDicNodeAsMatch(DicTraverseSession *traverseSession, 74 DicNode *childDicNode) const; 75 76 static const int MIN_CONTINUOUS_SUGGESTION_INPUT_SIZE; 77 78 const Traversal *const TRAVERSAL; 79 const Scoring *const SCORING; 80 const Weighting *const WEIGHTING; 81 }; 82 } // namespace latinime 83 #endif // LATINIME_SUGGEST_IMPL_H 84