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 24namespace latinime { 25 26class 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_CASE_ERROR; 34 static const ErrorType MATCH_WITH_ACCENT_ERROR; 35 static const ErrorType MATCH_WITH_DIGRAPH; 36 // Treat error as an intentional omission when the CorrectionType is omission and the node can 37 // be intentional omission. 38 static const ErrorType INTENTIONAL_OMISSION; 39 // Substitution, omission and transposition 40 static const ErrorType EDIT_CORRECTION; 41 // Proximity error 42 static const ErrorType PROXIMITY_CORRECTION; 43 // Completion 44 static const ErrorType COMPLETION; 45 // New word 46 // TODO: Remove. 47 // A new word error should be an edit correction error or a proximity correction error. 48 static const ErrorType NEW_WORD; 49 50 static bool isExactMatch(const ErrorType containedErrorTypes) { 51 return (containedErrorTypes & ~ERRORS_TREATED_AS_AN_EXACT_MATCH) == 0; 52 } 53 54 static bool isExactMatchWithIntentionalOmission(const ErrorType containedErrorTypes) { 55 return (containedErrorTypes 56 & ~ERRORS_TREATED_AS_AN_EXACT_MATCH_WITH_INTENTIONAL_OMISSION) == 0; 57 } 58 59 static bool isEditCorrectionError(const ErrorType errorType) { 60 return (errorType & EDIT_CORRECTION) != 0; 61 } 62 63 static bool isProximityCorrectionError(const ErrorType errorType) { 64 return (errorType & PROXIMITY_CORRECTION) != 0; 65 } 66 67 static bool isCompletion(const ErrorType errorType) { 68 return (errorType & COMPLETION) != 0; 69 } 70 71 private: 72 DISALLOW_IMPLICIT_CONSTRUCTORS(ErrorTypeUtils); 73 74 static const ErrorType ERRORS_TREATED_AS_AN_EXACT_MATCH; 75 static const ErrorType ERRORS_TREATED_AS_AN_EXACT_MATCH_WITH_INTENTIONAL_OMISSION; 76}; 77} // namespace latinime 78#endif // LATINIME_ERROR_TYPE_UTILS_H 79