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

Side by Side Diff: third_party/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: 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 unified diff | Download patch
OLDNEW
(Empty)
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_DAEMARU_LEVENSHTEIN_EDIT_DISTANCE_POLICY_H
18 #define LATINIME_DAEMARU_LEVENSHTEIN_EDIT_DISTANCE_POLICY_H
19
20 #include "third_party/prediction/suggest/policyimpl/utils/edit_distance_policy.h "
21 #include "third_party/prediction/utils/char_utils.h"
22
23 namespace latinime {
24
25 class DamerauLevenshteinEditDistancePolicy : public EditDistancePolicy {
26 public:
27 DamerauLevenshteinEditDistancePolicy(const int* const string0,
28 const int length0,
29 const int* const string1,
30 const int length1)
31 : mString0(string0),
32 mString0Length(length0),
33 mString1(string1),
34 mString1Length(length1) {}
35 ~DamerauLevenshteinEditDistancePolicy() {}
36
37 AK_FORCE_INLINE float getSubstitutionCost(const int index0,
38 const int index1) const {
39 const int c0 = CharUtils::toBaseLowerCase(mString0[index0]);
40 const int c1 = CharUtils::toBaseLowerCase(mString1[index1]);
41 return (c0 == c1) ? 0.0f : 1.0f;
42 }
43
44 AK_FORCE_INLINE float getDeletionCost(const int index0,
45 const int index1) const {
46 return 1.0f;
47 }
48
49 AK_FORCE_INLINE float getInsertionCost(const int index0,
50 const int index1) const {
51 return 1.0f;
52 }
53
54 AK_FORCE_INLINE bool allowTransposition(const int index0,
55 const int index1) const {
56 const int c0 = CharUtils::toBaseLowerCase(mString0[index0]);
57 const int c1 = CharUtils::toBaseLowerCase(mString1[index1]);
58 if (index0 > 0 && index1 > 0 &&
59 c0 == CharUtils::toBaseLowerCase(mString1[index1 - 1]) &&
60 c1 == CharUtils::toBaseLowerCase(mString0[index0 - 1])) {
61 return true;
62 }
63 return false;
64 }
65
66 AK_FORCE_INLINE float getTranspositionCost(const int index0,
67 const int index1) const {
68 return getSubstitutionCost(index0, index1);
69 }
70
71 AK_FORCE_INLINE int getString0Length() const { return mString0Length; }
72
73 AK_FORCE_INLINE int getString1Length() const { return mString1Length; }
74
75 private:
76 DISALLOW_COPY_AND_ASSIGN(DamerauLevenshteinEditDistancePolicy);
77
78 const int* const mString0;
79 const int mString0Length;
80 const int* const mString1;
81 const int mString1Length;
82 };
83 } // namespace latinime
84
85 #endif // LATINIME_DAEMARU_LEVENSHTEIN_EDIT_DISTANCE_POLICY_H
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698