1 /* 2 * Copyright (C) 2013 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_ERROR_TYPE_UTILS_H 18 #define LATINIME_ERROR_TYPE_UTILS_H 19 20 #include <cstdint> 21 22 #include "defines.h" 23 24 namespace latinime { 25 26 class ErrorTypeUtils { 27 public: 28 // ErrorType is mainly decided by CorrectionType but it is also depending on if 29 // the correction has really been performed or not. 30 typedef uint32_t ErrorType; 31 32 static const ErrorType NOT_AN_ERROR; 33 static const ErrorType MATCH_WITH_WRONG_CASE; 34 static const ErrorType MATCH_WITH_MISSING_ACCENT; 35 static const ErrorType MATCH_WITH_MISSING_EXPLICIT_ACCENT; 36 static const ErrorType MATCH_WITH_WRONG_ACCENT; 37 static const ErrorType MATCH_WITH_DIGRAPH; 38 // Treat error as an intentional omission when the CorrectionType is omission and the node can 39 // be intentional omission. 40 static const ErrorType INTENTIONAL_OMISSION; 41 // Substitution, omission and transposition 42 static const ErrorType EDIT_CORRECTION; 43 // Proximity error 44 static const ErrorType PROXIMITY_CORRECTION; 45 // Completion 46 static const ErrorType COMPLETION; 47 // New word 48 // TODO: Remove. 49 // A new word error should be an edit correction error or a proximity correction error. 50 static const ErrorType NEW_WORD; 51 isExactMatch(const ErrorType containedErrorTypes)52 static bool isExactMatch(const ErrorType containedErrorTypes) { 53 return (containedErrorTypes & ~ERRORS_TREATED_AS_AN_EXACT_MATCH) == 0; 54 } 55 isPerfectMatch(const ErrorType containedErrorTypes)56 static bool isPerfectMatch(const ErrorType containedErrorTypes) { 57 return (containedErrorTypes & ~ERRORS_TREATED_AS_A_PERFECT_MATCH) == 0; 58 } 59 isExactMatchWithIntentionalOmission(const ErrorType containedErrorTypes)60 static bool isExactMatchWithIntentionalOmission(const ErrorType containedErrorTypes) { 61 return (containedErrorTypes 62 & ~ERRORS_TREATED_AS_AN_EXACT_MATCH_WITH_INTENTIONAL_OMISSION) == 0; 63 } 64 isMissingExplicitAccent(const ErrorType errorType)65 static bool isMissingExplicitAccent(const ErrorType errorType) { 66 return (errorType & MATCH_WITH_MISSING_EXPLICIT_ACCENT) != 0; 67 } 68 isEditCorrectionError(const ErrorType errorType)69 static bool isEditCorrectionError(const ErrorType errorType) { 70 return (errorType & EDIT_CORRECTION) != 0; 71 } 72 isProximityCorrectionError(const ErrorType errorType)73 static bool isProximityCorrectionError(const ErrorType errorType) { 74 return (errorType & PROXIMITY_CORRECTION) != 0; 75 } 76 isCompletion(const ErrorType errorType)77 static bool isCompletion(const ErrorType errorType) { 78 return (errorType & COMPLETION) != 0; 79 } 80 81 private: 82 DISALLOW_IMPLICIT_CONSTRUCTORS(ErrorTypeUtils); 83 84 static const ErrorType ERRORS_TREATED_AS_AN_EXACT_MATCH; 85 static const ErrorType ERRORS_TREATED_AS_A_PERFECT_MATCH; 86 static const ErrorType ERRORS_TREATED_AS_AN_EXACT_MATCH_WITH_INTENTIONAL_OMISSION; 87 }; 88 } // namespace latinime 89 #endif // LATINIME_ERROR_TYPE_UTILS_H 90