Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(628)

Unified Diff: third_party/android_prediction/suggest/policyimpl/utils/damerau_levenshtein_edit_distance_policy.h

Issue 1247903003: Add spellcheck and word suggestion to the prediction service (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: format README and CHROMIUM.diff Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/android_prediction/suggest/policyimpl/utils/damerau_levenshtein_edit_distance_policy.h
diff --git a/third_party/android_prediction/suggest/policyimpl/utils/damerau_levenshtein_edit_distance_policy.h b/third_party/android_prediction/suggest/policyimpl/utils/damerau_levenshtein_edit_distance_policy.h
new file mode 100644
index 0000000000000000000000000000000000000000..e791d708dc31466d9124e25833f4ad8303b3ee60
--- /dev/null
+++ b/third_party/android_prediction/suggest/policyimpl/utils/damerau_levenshtein_edit_distance_policy.h
@@ -0,0 +1,79 @@
+/*
+ * Copyright (C) 2013 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef LATINIME_DAEMARU_LEVENSHTEIN_EDIT_DISTANCE_POLICY_H
+#define LATINIME_DAEMARU_LEVENSHTEIN_EDIT_DISTANCE_POLICY_H
+
+#include "third_party/android_prediction/suggest/policyimpl/utils/edit_distance_policy.h"
+#include "third_party/android_prediction/utils/char_utils.h"
+
+namespace latinime {
+
+class DamerauLevenshteinEditDistancePolicy : public EditDistancePolicy {
+ public:
+ DamerauLevenshteinEditDistancePolicy(const int *const string0, const int length0,
+ const int *const string1, const int length1)
+ : mString0(string0), mString0Length(length0), mString1(string1),
+ mString1Length(length1) {}
+ ~DamerauLevenshteinEditDistancePolicy() {}
+
+ AK_FORCE_INLINE float getSubstitutionCost(const int index0, const int index1) const {
+ const int c0 = CharUtils::toBaseLowerCase(mString0[index0]);
+ const int c1 = CharUtils::toBaseLowerCase(mString1[index1]);
+ return (c0 == c1) ? 0.0f : 1.0f;
+ }
+
+ AK_FORCE_INLINE float getDeletionCost(const int index0, const int index1) const {
+ return 1.0f;
+ }
+
+ AK_FORCE_INLINE float getInsertionCost(const int index0, const int index1) const {
+ return 1.0f;
+ }
+
+ AK_FORCE_INLINE bool allowTransposition(const int index0, const int index1) const {
+ const int c0 = CharUtils::toBaseLowerCase(mString0[index0]);
+ const int c1 = CharUtils::toBaseLowerCase(mString1[index1]);
+ if (index0 > 0 && index1 > 0 && c0 == CharUtils::toBaseLowerCase(mString1[index1 - 1])
+ && c1 == CharUtils::toBaseLowerCase(mString0[index0 - 1])) {
+ return true;
+ }
+ return false;
+ }
+
+ AK_FORCE_INLINE float getTranspositionCost(const int index0, const int index1) const {
+ return getSubstitutionCost(index0, index1);
+ }
+
+ AK_FORCE_INLINE int getString0Length() const {
+ return mString0Length;
+ }
+
+ AK_FORCE_INLINE int getString1Length() const {
+ return mString1Length;
+ }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN (DamerauLevenshteinEditDistancePolicy);
+
+ const int *const mString0;
+ const int mString0Length;
+ const int *const mString1;
+ const int mString1Length;
+};
+} // namespace latinime
+
+#endif // LATINIME_DAEMARU_LEVENSHTEIN_EDIT_DISTANCE_POLICY_H

Powered by Google App Engine
This is Rietveld 408576698