error_type_utils.h revision 18ba146b72c5ff645d57e72fd1861ac59c3b7257
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 <stdint.h> 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 isEditCorrectionError(const ErrorType errorType) { 55 return (errorType & EDIT_CORRECTION) != 0; 56 } 57 58 static bool isProximityCorrectionError(const ErrorType errorType) { 59 return (errorType & PROXIMITY_CORRECTION) != 0; 60 } 61 62 static bool isCompletion(const ErrorType errorType) { 63 return (errorType & COMPLETION) != 0; 64 } 65 66 private: 67 DISALLOW_IMPLICIT_CONSTRUCTORS(ErrorTypeUtils); 68 69 static const ErrorType ERRORS_TREATED_AS_AN_EXACT_MATCH; 70}; 71} // namespace latinime 72#endif // LATINIME_ERROR_TYPE_UTILS_H 73