|
| 1 | +// Copyright 2010-2021, Google Inc. |
| 2 | +// All rights reserved. |
| 3 | +// |
| 4 | +// Redistribution and use in source and binary forms, with or without |
| 5 | +// modification, are permitted provided that the following conditions are |
| 6 | +// met: |
| 7 | +// |
| 8 | +// * Redistributions of source code must retain the above copyright |
| 9 | +// notice, this list of conditions and the following disclaimer. |
| 10 | +// * Redistributions in binary form must reproduce the above |
| 11 | +// copyright notice, this list of conditions and the following disclaimer |
| 12 | +// in the documentation and/or other materials provided with the |
| 13 | +// distribution. |
| 14 | +// * Neither the name of Google Inc. nor the names of its |
| 15 | +// contributors may be used to endorse or promote products derived from |
| 16 | +// this software without specific prior written permission. |
| 17 | +// |
| 18 | +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 19 | +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 20 | +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 21 | +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 22 | +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 | +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 | +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 | +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 | +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 | +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 | +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 | + |
| 30 | +#ifndef MOZC_REQUEST_OPTIONS_H_ |
| 31 | +#define MOZC_REQUEST_OPTIONS_H_ |
| 32 | + |
| 33 | +#include <cstddef> |
| 34 | +#include <cstdint> |
| 35 | +#include <type_traits> |
| 36 | + |
| 37 | +namespace mozc { |
| 38 | + |
| 39 | +inline constexpr size_t kMaxConversionCandidatesSize = 200; |
| 40 | + |
| 41 | +enum RequestType { |
| 42 | + CONVERSION, // normal conversion |
| 43 | + REVERSE_CONVERSION, // reverse conversion |
| 44 | + PREDICTION, // show prediction with user tab key |
| 45 | + SUGGESTION, // show prediction automatically |
| 46 | + PARTIAL_PREDICTION, // show prediction using the text before cursor |
| 47 | + PARTIAL_SUGGESTION, // show suggestion using the text before cursor |
| 48 | +}; |
| 49 | + |
| 50 | +enum ComposerKeySelection { |
| 51 | + // Use Composer::GetQueryForConversion() to generate conversion key. This |
| 52 | + // option uses the exact composition which user sees, e.g., "とうk". |
| 53 | + CONVERSION_KEY, |
| 54 | + |
| 55 | + // Use Composer::GetQueryForPrediction() to generate conversion key. This |
| 56 | + // option trims the trailing unresolved romaji. For example, if composition |
| 57 | + // is "とうk", the conversion key becomes "とう". This option is mainly used |
| 58 | + // in dictionary_predictor.cc for realtime conversion. |
| 59 | + PREDICTION_KEY, |
| 60 | + |
| 61 | + // TODO(team): We may want to implement other options. For instance, |
| 62 | + // Composer::GetQueriesForPrediction() expands the trailing romaji to a set |
| 63 | + // of possible hiragana. |
| 64 | +}; |
| 65 | + |
| 66 | +// Options must be trivially copyable to get hash value directly. |
| 67 | +struct ConversionOptions { |
| 68 | + RequestType request_type = CONVERSION; |
| 69 | + |
| 70 | + // Which composer's method to use for conversion key; see the comment around |
| 71 | + // the definition of ComposerKeySelection above. |
| 72 | + ComposerKeySelection composer_key_selection = CONVERSION_KEY; |
| 73 | + |
| 74 | + int max_conversion_candidates_size = kMaxConversionCandidatesSize; |
| 75 | + int max_user_history_prediction_candidates_size = 3; |
| 76 | + int max_user_history_prediction_candidates_size_for_zero_query = 4; |
| 77 | + int max_dictionary_prediction_candidates_size = 20; |
| 78 | + |
| 79 | + // If true, insert a top candidate from the actual (non-immutable) converter |
| 80 | + // to realtime conversion results. Note that setting this true causes a big |
| 81 | + // performance loss (3 times slower). |
| 82 | + bool use_actual_converter_for_realtime_conversion = false; |
| 83 | + |
| 84 | + // Don't use this flag directly. This flag is used by DictionaryPredictor to |
| 85 | + // skip some heavy rewriters, such as UserBoundaryHistoryRewriter and |
| 86 | + // TransliterationRewriter. |
| 87 | + // TODO(noriyukit): Fix such a hacky handling for realtime conversion. |
| 88 | + bool skip_slow_rewriters = false; |
| 89 | + |
| 90 | + // If true, partial candidates are created on prediction/suggestion. |
| 91 | + // For example, "私の" is created from composition "わたしのなまえ". |
| 92 | + bool create_partial_candidates = false; |
| 93 | + |
| 94 | + // If false, stop using user history for conversion. |
| 95 | + // This is used for supporting CONVERT_WITHOUT_HISTORY command. |
| 96 | + // Please refer to session/internal/keymap.h |
| 97 | + bool enable_user_history_for_conversion = true; |
| 98 | + |
| 99 | + // If true, enable kana modifier insensitive conversion. |
| 100 | + bool kana_modifier_insensitive_conversion = true; |
| 101 | + |
| 102 | + // If true, use conversion_segment(0).key() instead of ComposerData. |
| 103 | + // TODO(b/365909808): Create a new string field to store the key. |
| 104 | + bool use_already_typing_corrected_key = false; |
| 105 | + |
| 106 | + // Enables incognito mode even when Config.incognito_mode() or |
| 107 | + // Request.is_incognito_mode() is false. Use this flag to dynamically change |
| 108 | + // the incognito_mode per client request. |
| 109 | + bool incognito_mode = false; |
| 110 | + |
| 111 | + // Overrides the bos_id to a specific POS id to specify the context |
| 112 | + // information. Note that the bos_id must be in the valid range. |
| 113 | + // POS id 0 is reserved for the default BOS/EOS. |
| 114 | + uint16_t bos_id = 0; |
| 115 | + |
| 116 | + // Disables to add prefix penalty. |
| 117 | + // Used to calculate the cost of a suffix of a word. |
| 118 | + bool disable_prefix_penalty = false; |
| 119 | + |
| 120 | + // This conversion request is called by predictor for realtime conversion. |
| 121 | + bool used_in_predictor_realtime_conversion = false; |
| 122 | +}; |
| 123 | + |
| 124 | +static_assert(std::is_trivially_copyable<ConversionOptions>::value, |
| 125 | + "ConversionOptions must be trivially copyable"); |
| 126 | + |
| 127 | +} // namespace mozc |
| 128 | + |
| 129 | +#endif // MOZC_REQUEST_OPTIONS_H_ |
0 commit comments