| OLD | NEW |
| (Empty) | |
| 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 #include "third_party/prediction/suggest/policyimpl/typing/typing_weighting.h" |
| 18 |
| 19 #include "third_party/prediction/suggest/core/dicnode/dic_node.h" |
| 20 #include "third_party/prediction/suggest/policyimpl/typing/scoring_params.h" |
| 21 |
| 22 namespace latinime { |
| 23 |
| 24 const TypingWeighting TypingWeighting::sInstance; |
| 25 |
| 26 ErrorTypeUtils::ErrorType TypingWeighting::getErrorType( |
| 27 const CorrectionType correctionType, |
| 28 const DicTraverseSession* const traverseSession, |
| 29 const DicNode* const parentDicNode, |
| 30 const DicNode* const dicNode) const { |
| 31 switch (correctionType) { |
| 32 case CT_MATCH: |
| 33 if (isProximityDicNode(traverseSession, dicNode)) { |
| 34 return ErrorTypeUtils::PROXIMITY_CORRECTION; |
| 35 } else if (dicNode->isInDigraph()) { |
| 36 return ErrorTypeUtils::MATCH_WITH_DIGRAPH; |
| 37 } else { |
| 38 // Compare the node code point with original primary code point on the |
| 39 // keyboard. |
| 40 const ProximityInfoState* const pInfoState = |
| 41 traverseSession->getProximityInfoState(0); |
| 42 const int primaryOriginalCodePoint = |
| 43 pInfoState->getPrimaryOriginalCodePointAt( |
| 44 dicNode->getInputIndex(0)); |
| 45 const int nodeCodePoint = dicNode->getNodeCodePoint(); |
| 46 if (primaryOriginalCodePoint == nodeCodePoint) { |
| 47 // Node code point is same as original code point on the keyboard. |
| 48 return ErrorTypeUtils::NOT_AN_ERROR; |
| 49 } else if (CharUtils::toLowerCase(primaryOriginalCodePoint) == |
| 50 CharUtils::toLowerCase(nodeCodePoint)) { |
| 51 // Only cases of the code points are different. |
| 52 return ErrorTypeUtils::MATCH_WITH_CASE_ERROR; |
| 53 } else if (CharUtils::toBaseCodePoint(primaryOriginalCodePoint) == |
| 54 CharUtils::toBaseCodePoint(nodeCodePoint)) { |
| 55 // Node code point is a variant of original code point. |
| 56 return ErrorTypeUtils::MATCH_WITH_ACCENT_ERROR; |
| 57 } else { |
| 58 // Node code point is a variant of original code point and the cases |
| 59 // are also |
| 60 // different. |
| 61 return ErrorTypeUtils::MATCH_WITH_ACCENT_ERROR | |
| 62 ErrorTypeUtils::MATCH_WITH_CASE_ERROR; |
| 63 } |
| 64 } |
| 65 break; |
| 66 case CT_ADDITIONAL_PROXIMITY: |
| 67 return ErrorTypeUtils::PROXIMITY_CORRECTION; |
| 68 case CT_OMISSION: |
| 69 if (parentDicNode->canBeIntentionalOmission()) { |
| 70 return ErrorTypeUtils::INTENTIONAL_OMISSION; |
| 71 } else { |
| 72 return ErrorTypeUtils::EDIT_CORRECTION; |
| 73 } |
| 74 break; |
| 75 case CT_SUBSTITUTION: |
| 76 case CT_INSERTION: |
| 77 case CT_TERMINAL_INSERTION: |
| 78 case CT_TRANSPOSITION: |
| 79 return ErrorTypeUtils::EDIT_CORRECTION; |
| 80 case CT_NEW_WORD_SPACE_OMISSION: |
| 81 case CT_NEW_WORD_SPACE_SUBSTITUTION: |
| 82 return ErrorTypeUtils::NEW_WORD; |
| 83 case CT_TERMINAL: |
| 84 return ErrorTypeUtils::NOT_AN_ERROR; |
| 85 case CT_COMPLETION: |
| 86 return ErrorTypeUtils::COMPLETION; |
| 87 default: |
| 88 return ErrorTypeUtils::NOT_AN_ERROR; |
| 89 } |
| 90 } |
| 91 } // namespace latinime |
| OLD | NEW |