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

Side by Side Diff: third_party/prediction/suggest/core/result/suggestion_results.cpp

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) 2014 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 #include "third_party/prediction/suggest/core/result/suggestion_results.h"
18
19 namespace latinime {
20
21 void SuggestionResults::addPrediction(const int* const codePoints,
22 const int codePointCount,
23 const int probability) {
24 if (probability == NOT_A_PROBABILITY) {
25 // Invalid word.
26 return;
27 }
28 addSuggestion(codePoints, codePointCount, probability,
29 Dictionary::KIND_PREDICTION, NOT_AN_INDEX,
30 NOT_A_FIRST_WORD_CONFIDENCE);
31 }
32
33 void SuggestionResults::addSuggestion(
34 const int* const codePoints,
35 const int codePointCount,
36 const int score,
37 const int type,
38 const int indexToPartialCommit,
39 const int autocimmitFirstWordConfindence) {
40 if (codePointCount <= 0 || codePointCount > MAX_WORD_LENGTH) {
41 // Invalid word.
42 AKLOGE(
43 "Invalid word is added to the suggestion results. codePointCount: %d",
44 codePointCount);
45 return;
46 }
47 if (getSuggestionCount() >= mMaxSuggestionCount) {
48 const SuggestedWord& mWorstSuggestion = mSuggestedWords.top();
49 if (score > mWorstSuggestion.getScore() ||
50 (score == mWorstSuggestion.getScore() &&
51 codePointCount < mWorstSuggestion.getCodePointCount())) {
52 mSuggestedWords.pop();
53 } else {
54 return;
55 }
56 }
57 mSuggestedWords.push(SuggestedWord(codePoints, codePointCount, score, type,
58 indexToPartialCommit,
59 autocimmitFirstWordConfindence));
60 }
61
62 void SuggestionResults::getSortedScores(int* const outScores) const {
63 auto copyOfSuggestedWords = mSuggestedWords;
64 while (!copyOfSuggestedWords.empty()) {
65 const SuggestedWord& suggestedWord = copyOfSuggestedWords.top();
66 outScores[copyOfSuggestedWords.size() - 1] = suggestedWord.getScore();
67 copyOfSuggestedWords.pop();
68 }
69 }
70
71 void SuggestionResults::dumpSuggestions() const {
72 AKLOGE("language weight: %f", mLanguageWeight);
73 std::vector<SuggestedWord> suggestedWords;
74 auto copyOfSuggestedWords = mSuggestedWords;
75 while (!copyOfSuggestedWords.empty()) {
76 suggestedWords.push_back(copyOfSuggestedWords.top());
77 copyOfSuggestedWords.pop();
78 }
79 int index = 0;
80 for (auto it = suggestedWords.rbegin(); it != suggestedWords.rend(); ++it) {
81 DUMP_SUGGESTION(it->getCodePoint(), it->getCodePointCount(), index,
82 it->getScore());
83 index++;
84 }
85 }
86
87 } // namespace latinime
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698