Refactor ProximityType and CorrectionType

Bug: 8277656
Change-Id: Ia7940bbf81fcf4ff5eb7869b105d98aa34155d33
diff --git a/native/jni/src/correction.cpp b/native/jni/src/correction.cpp
index b8690eb..0ae02d5 100644
--- a/native/jni/src/correction.cpp
+++ b/native/jni/src/correction.cpp
@@ -190,11 +190,11 @@
 }
 
 inline static bool isEquivalentChar(ProximityType type) {
-    return type == EQUIVALENT_CHAR;
+    return type == MATCH_CHAR;
 }
 
 inline static bool isProximityCharOrEquivalentChar(ProximityType type) {
-    return type == EQUIVALENT_CHAR || type == NEAR_PROXIMITY_CHAR;
+    return type == MATCH_CHAR || type == PROXIMITY_CHAR;
 }
 
 Correction::CorrectionType Correction::processCharAndCalcState(const int c, const bool isTerminal) {
@@ -221,7 +221,7 @@
                 --mExcessiveCount;
                 mDistances[mOutputIndex] =
                         mProximityInfoState.getNormalizedSquaredDistance(mInputIndex, 0);
-            } else if (matchId == NEAR_PROXIMITY_CHAR) {
+            } else if (matchId == PROXIMITY_CHAR) {
                 mLastCharExceeded = false;
                 --mExcessiveCount;
                 ++mProximityCount;
@@ -299,11 +299,11 @@
             : (noCorrectionsHappenedSoFar && mProximityCount == 0);
 
     ProximityType matchedProximityCharId = secondTransposing
-            ? EQUIVALENT_CHAR
+            ? MATCH_CHAR
             : mProximityInfoState.getProximityType(
                     mInputIndex, c, checkProximityChars, &proximityIndex);
 
-    if (UNRELATED_CHAR == matchedProximityCharId
+    if (SUBSTITUTION_CHAR == matchedProximityCharId
             || ADDITIONAL_PROXIMITY_CHAR == matchedProximityCharId) {
         if (canTryCorrection && mOutputIndex > 0
                 && mCorrectionStates[mOutputIndex].mProximityMatching
@@ -332,7 +332,7 @@
         }
     }
 
-    if (UNRELATED_CHAR == matchedProximityCharId
+    if (SUBSTITUTION_CHAR == matchedProximityCharId
             || ADDITIONAL_PROXIMITY_CHAR == matchedProximityCharId) {
         if (ADDITIONAL_PROXIMITY_CHAR == matchedProximityCharId) {
             mAdditionalProximityMatching = true;
@@ -455,7 +455,7 @@
         mMatching = true;
         ++mEquivalentCharCount;
         mDistances[mOutputIndex] = mProximityInfoState.getNormalizedSquaredDistance(mInputIndex, 0);
-    } else if (NEAR_PROXIMITY_CHAR == matchedProximityCharId) {
+    } else if (PROXIMITY_CHAR == matchedProximityCharId) {
         mProximityMatching = true;
         ++mProximityCount;
         mDistances[mOutputIndex] =
@@ -614,7 +614,7 @@
         multiplyIntCapped(matchWeight, &finalFreq);
     }
 
-    if (proximityInfoState->getProximityType(0, word[0], true) == UNRELATED_CHAR) {
+    if (proximityInfoState->getProximityType(0, word[0], true) == SUBSTITUTION_CHAR) {
         multiplyRate(FIRST_CHAR_DIFFERENT_DEMOTION_RATE, &finalFreq);
     }
 
diff --git a/native/jni/src/defines.h b/native/jni/src/defines.h
index 11dc3d2..0aedc28 100644
--- a/native/jni/src/defines.h
+++ b/native/jni/src/defines.h
@@ -275,7 +275,7 @@
 #define NOT_A_CODE_POINT (-1)
 #define NOT_A_DISTANCE (-1)
 #define NOT_A_COORDINATE (-1)
-#define EQUIVALENT_CHAR_WITHOUT_DISTANCE_INFO (-2)
+#define MATCH_CHAR_WITHOUT_DISTANCE_INFO (-2)
 #define PROXIMITY_CHAR_WITHOUT_DISTANCE_INFO (-3)
 #define ADDITIONAL_PROXIMITY_CHAR_DISTANCE_INFO (-4)
 #define NOT_AN_INDEX (-1)
@@ -396,15 +396,15 @@
 // Used as a return value for character comparison
 typedef enum {
     // Same char, possibly with different case or accent
-    EQUIVALENT_CHAR,
+    MATCH_CHAR,
     // It is a char located nearby on the keyboard
-    NEAR_PROXIMITY_CHAR,
-    // It is an unrelated char and could be a substitution char
-    UNRELATED_CHAR,
-    // It is an unrelated char nor a substitution char
-    UNRELATED_NOR_SUBSTITUTION_CHAR,
+    PROXIMITY_CHAR,
     // Additional proximity char which can differ by language.
-    ADDITIONAL_PROXIMITY_CHAR
+    ADDITIONAL_PROXIMITY_CHAR,
+    // It is a substitution char
+    SUBSTITUTION_CHAR,
+    // It is an unrelated char
+    UNRELATED_CHAR,
 } ProximityType;
 
 typedef enum {
@@ -415,15 +415,16 @@
 
 typedef enum {
     CT_MATCH,
+    CT_PROXIMITY,
+    CT_ADDITIONAL_PROXIMITY,
+    CT_SUBSTITUTION,
     CT_OMISSION,
     CT_INSERTION,
     CT_TRANSPOSITION,
-    CT_SUBSTITUTION,
     CT_SPACE_SUBSTITUTION,
     CT_SPACE_OMISSION,
     CT_COMPLETION,
     CT_TERMINAL,
     CT_NEW_WORD,
-    CT_NEW_WORD_BIGRAM,
 } CorrectionType;
 #endif // LATINIME_DEFINES_H
diff --git a/native/jni/src/proximity_info_state.cpp b/native/jni/src/proximity_info_state.cpp
index 7ec3c54..fe1c433 100644
--- a/native/jni/src/proximity_info_state.cpp
+++ b/native/jni/src/proximity_info_state.cpp
@@ -197,15 +197,15 @@
     // The first char in the array is what user typed. If it matches right away, that means the
     // user typed that same char for this pos.
     if (firstCodePoint == baseLowerC || firstCodePoint == codePoint) {
-        return EQUIVALENT_CHAR;
+        return MATCH_CHAR;
     }
 
-    if (!checkProximityChars) return UNRELATED_CHAR;
+    if (!checkProximityChars) return SUBSTITUTION_CHAR;
 
     // If the non-accented, lowercased version of that first character matches c, then we have a
     // non-accented version of the accented character the user typed. Treat it as a close char.
     if (toBaseLowerCase(firstCodePoint) == baseLowerC) {
-        return NEAR_PROXIMITY_CHAR;
+        return PROXIMITY_CHAR;
     }
 
     // Not an exact nor an accent-alike match: search the list of close keys
@@ -218,7 +218,7 @@
             if (proximityIndex) {
                 *proximityIndex = j;
             }
-            return NEAR_PROXIMITY_CHAR;
+            return PROXIMITY_CHAR;
         }
         ++j;
     }
@@ -238,23 +238,23 @@
             ++j;
         }
     }
-    // Was not included, signal this as an unrelated character.
-    return UNRELATED_CHAR;
+    // Was not included, signal this as a substitution character.
+    return SUBSTITUTION_CHAR;
 }
 
 ProximityType ProximityInfoState::getProximityTypeG(const int index, const int codePoint) const {
     if (!isUsed()) {
-        return UNRELATED_NOR_SUBSTITUTION_CHAR;
+        return UNRELATED_CHAR;
     }
     const int lowerCodePoint = toLowerCase(codePoint);
     const int baseLowerCodePoint = toBaseCodePoint(lowerCodePoint);
     for (int i = 0; i < static_cast<int>(mSampledSearchKeyVectors[index].size()); ++i) {
         if (mSampledSearchKeyVectors[index][i] == lowerCodePoint
                 || mSampledSearchKeyVectors[index][i] == baseLowerCodePoint) {
-            return EQUIVALENT_CHAR;
+            return MATCH_CHAR;
         }
     }
-    return UNRELATED_NOR_SUBSTITUTION_CHAR;
+    return UNRELATED_CHAR;
 }
 
 bool ProximityInfoState::isKeyInSerchKeysAfterIndex(const int index, const int keyId) const {
diff --git a/native/jni/src/proximity_info_state_utils.cpp b/native/jni/src/proximity_info_state_utils.cpp
index 7cbc88c..ccb28bc 100644
--- a/native/jni/src/proximity_info_state_utils.cpp
+++ b/native/jni/src/proximity_info_state_utils.cpp
@@ -209,7 +209,7 @@
                                 * ProximityInfoParams::NORMALIZED_SQUARED_DISTANCE_SCALING_FACTOR);
             } else {
                 normalizedSquaredDistances[i * MAX_PROXIMITY_CHARS_SIZE + j] =
-                        (j == 0) ? EQUIVALENT_CHAR_WITHOUT_DISTANCE_INFO :
+                        (j == 0) ? MATCH_CHAR_WITHOUT_DISTANCE_INFO :
                                 PROXIMITY_CHAR_WITHOUT_DISTANCE_INFO;
             }
             if (DEBUG_PROXIMITY_CHARS) {