1// Copyright 2010-2018, 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
30syntax = "proto2";
31
32package mozc.user_dictionary;
33
34option java_outer_classname = "ProtoUserDictionaryStorage";
35option java_package = "org.mozc.android.inputmethod.japanese.protobuf";
36
37message UserDictionary {
38  enum PosType {
39    NOUN = 1;  // "名詞"
40    ABBREVIATION = 2;  // "短縮よみ"
41    SUGGESTION_ONLY = 3;  // "サジェストのみ"
42    PROPER_NOUN = 4;  // "固有名詞"
43    PERSONAL_NAME = 5;  // "人名"
44    FAMILY_NAME = 6;  // "姓"
45    FIRST_NAME = 7;  // "名"
46    ORGANIZATION_NAME = 8;  // "組織"
47    PLACE_NAME = 9;  // "地名"
48    SA_IRREGULAR_CONJUGATION_NOUN = 10;  // "名詞サ変"
49    ADJECTIVE_VERBAL_NOUN = 11;  // "名詞形動"
50    NUMBER = 12;  // "数"
51    ALPHABET = 13;  // "アルファベット"
52    SYMBOL = 14;  // "記号"
53    EMOTICON = 15;  // "顔文字"
54
55    ADVERB = 16;  // "副詞"
56    PRENOUN_ADJECTIVAL = 17;  // "連体詞"
57    CONJUNCTION = 18;  // "接続詞"
58    INTERJECTION = 19;  // "感動詞"
59
60    PREFIX = 20;  // "接頭語"
61    COUNTER_SUFFIX = 21;  // "助数詞"
62    GENERIC_SUFFIX = 22;  // "接尾一般"
63    PERSON_NAME_SUFFIX = 23;  // "接尾人名"
64    PLACE_NAME_SUFFIX = 24;  // "接尾地名"
65
66    WA_GROUP1_VERB = 25;  // "動詞ワ行五段"
67    KA_GROUP1_VERB = 26;  // "動詞カ行五段"
68    SA_GROUP1_VERB = 27;  // "動詞サ行五段"
69    TA_GROUP1_VERB = 28;  // "動詞タ行五段"
70    NA_GROUP1_VERB = 29;  // "動詞ナ行五段"
71    MA_GROUP1_VERB = 30;  // "動詞マ行五段"
72    RA_GROUP1_VERB = 31;  // "動詞ラ行五段"
73    GA_GROUP1_VERB = 32;  // "動詞ガ行五段"
74    BA_GROUP1_VERB = 33;  // "動詞バ行五段"
75    HA_GROUP1_VERB = 34;  // "動詞ハ行四段"
76    GROUP2_VERB = 35;  // "動詞一段"
77    KURU_GROUP3_VERB = 36;  // "動詞カ変"
78    SURU_GROUP3_VERB = 37;  // "動詞サ変"
79    ZURU_GROUP3_VERB = 38;  // "動詞ザ変"
80    RU_GROUP3_VERB = 39;  // "動詞ラ変"
81
82    ADJECTIVE = 40;  // "形容詞"
83    SENTENCE_ENDING_PARTICLE = 41;  // "終助詞"
84    PUNCTUATION = 42;  // "句読点"
85    FREE_STANDING_WORD = 43;  // "独立語"
86
87    SUPPRESSION_WORD = 44;  // "抑制単語"
88  };
89
90  // ID of this dictionary
91  optional uint64 id = 1 [ default = 0 ];
92
93  // set false if this dictionary is not used.
94  // Even if |enabled| is false, the dictionary
95  // it self is visible to user.
96  optional bool enabled = 2 [ default = true ];
97
98  // name of dictionary
99  optional string name = 3 [ default = "" ];
100
101  // entry of each word
102  message Entry {
103    optional string key     = 1 [ default = "" ];
104    optional string value   = 2 [ default = "" ];
105    // Do NOT use tag number '3' in this proto. Please see below.
106    reserved 3;  // Deprecated pos
107    optional string comment = 4 [ default = "" ];
108
109    // Historically we used to use tag number '3' for POS in string format.
110    // In order to switch it to enum based POS, we removed (deprecated) the
111    // tag number '3' field and created another field numbered '5'.
112    optional PosType pos    = 5;
113
114    // set true if this entry is removed.
115    // This flag is used for cloud sync feature.
116    // Cloud sync feature is already deprecated and this flag is only
117    // used to convert sync dictionary to normal dictionary.
118    optional bool  removed  = 10 [ default = false ];
119
120    // set true if this entry is automatically registered
121    // by converter.
122    optional bool auto_registered = 11 [ default = false ];
123  };
124
125  repeated Entry entries = 4;
126
127  // set true if this dictionary is removed.
128  // This flag is used for cloud sync feature.
129  // Cloud sync feature is already deprecated and this flag is only
130  // used to convert sync dictionary to normal dictionary.
131  optional bool removed = 5 [ default = false ];
132
133  // This flag is used for cloud sync feature.
134  // Cloud sync feature is already deprecated and this flag is only
135  // used to convert sync dictionary to normal dictionary.
136  optional bool syncable = 6 [ default = false ];
137};
138
139message UserDictionaryStorage {
140  // version of user dictionary
141  optional int32 version = 1 [ default = 0 ];
142
143  // dictionary body
144  repeated UserDictionary dictionaries = 2;
145
146  enum StorageType {
147    SNAPSHOT = 1;   // This storage is a snapshot.
148    UPDATE = 2;     // This storage is a diff of some snapshots.
149  };
150
151  optional StorageType storage_type = 10 [ default = SNAPSHOT ];
152};
153
154message UserDictionaryCommand {
155  enum CommandType {
156    // Does nothing.
157    NO_OPERATION = 0;
158
159    // Unlink the user dictionary file if necessary.
160    // We can do this operation without creating a session.
161    // This operation is introduced as a last resort to clean up
162    // user dictionary, so it *forces* to unlink the file regardless
163    // of the current user dictionary session status.
164    CLEAR_STORAGE = 1;
165
166    // Creates a new session, and returns its id via
167    // UserDictionaryCommandStatus::session_id.
168    CREATE_SESSION = 2;
169
170    // Deletes the session identified by session_id.
171    DELETE_SESSION = 3;
172
173    // Sets the default dictionary name. It will be used when
174    // ensure_non_empty_storage is enabled and the operation supporting the
175    // flag is invoked.
176    SET_DEFAULT_DICTIONARY_NAME = 4;
177
178    // Checks if the session is currently undoable or not.
179    CHECK_UNDOABILITY = 5;
180
181    // Undoes the last operation.
182    UNDO = 6;
183
184    // Loads from local storage.
185    LOAD = 7;
186
187    // Saves to local storage.
188    SAVE = 8;
189
190    // Returns a list of name and dictionary-id pairs.
191    // They are filled in the form of UserDictionary without any entries
192    // in UserDictionaryCommandStatus::storage.
193    GET_USER_DICTIONARY_NAME_LIST = 9;
194
195    // Returns the number of entries in the dictionary with the
196    // given dictionary_id.
197    GET_ENTRY_SIZE = 10;
198
199    // Use GET_ENTRIES instead.
200    OBSOLETE_GET_ENTRY = 11;
201
202    // Returns if it is possible to add new dictionary or not.
203    // The result is returned by using status code.
204    CHECK_NEW_DICTIONARY_AVAILABILITY = 12;
205
206    // Creates a new dictionary with the dictionary_name.
207    CREATE_DICTIONARY = 13;
208
209    // Deletes the dictionary with the given dictionary_id.
210    DELETE_DICTIONARY = 14;
211
212    // Renames the dictionary with the given dictionary_id to dictionary_name.
213    RENAME_DICTIONARY = 15;
214
215    // Returns if it is possible to add new entry to the dictionary
216    // with the given dictionary_id or not.
217    CHECK_NEW_ENTRY_AVAILABILITY = 16;
218
219    // Adds an entry to the dictionary with the given dictionary_id.
220    // Added entry should be located at the end of the dictionary, and
221    // the data should be passed via entry field.
222    ADD_ENTRY = 17;
223
224    // Edits an entry in the dictionary with the given dictionary_id.
225    // The new data should be passed via entry.
226    // The edit target should be specified via entry_index(0).
227    EDIT_ENTRY = 18;
228
229    // Deletes entries in the dictionary with the given dictionary_id.
230    // The target entries should be specified based on index in entry_index.
231    DELETE_ENTRY = 19;
232
233    // Imports entries from the given data into a dictionary.
234    // There are two ways to specify the dictionary:
235    // 1) set dictionary_id for the dictionary
236    // 2) set dictionary_name to create a new dictionary with the name.
237    IMPORT_DATA = 20;
238
239    // Gets the entire UserDictionaryStorage data.
240    // Note: The result of this command could be too large for IPC, which has a
241    // size limitation of the response data.
242    GET_STORAGE = 21;
243
244    // Returns entries in the dictionary specified by dictionary_id.
245    // The position of the entry should be specified via entry_index().
246    GET_ENTRIES = 22;
247  };
248
249  required CommandType type = 1;
250  optional uint64 session_id = 2;
251  optional uint64 dictionary_id = 3;
252  optional string dictionary_name = 4;
253  repeated int32 entry_index = 5;
254  optional UserDictionary.Entry entry = 6;
255  optional string data = 7;
256  optional bool ensure_non_empty_storage = 8;
257  optional bool ignore_invalid_entries = 9;
258};
259
260message UserDictionaryCommandStatus {
261  // Note: this status code is now temporary assgined.
262  // It may be updated (incl. re-numbering) to organize the code.
263  // I.e., the code shouldn't be saved in serialized format for now.
264  // TODO(hidehiko): Re-organize and re-number the enum values,
265  //   after we check all necessary codes in.
266  enum Status {
267    // Note: SUCCEEDED is conflicting Windows MACRO.
268    USER_DICTIONARY_COMMAND_SUCCESS = 1;
269    UNKNOWN_ERROR = 2;
270
271    UNKNOWN_COMMAND = 3;
272    INVALID_ARGUMENT = 4;
273
274    UNKNOWN_SESSION_ID = 5;
275
276    FILE_NOT_FOUND = 6;
277    INVALID_FILE_FORMAT = 7;
278
279    // Note: currently if we recieve this error status,
280    // the file is actually saved.
281    FILE_SIZE_LIMIT_EXCEEDED = 8;
282    DICTIONARY_SIZE_LIMIT_EXCEEDED = 9;
283    ENTRY_SIZE_LIMIT_EXCEEDED = 10;
284
285    UNKNOWN_DICTIONARY_ID = 11;
286    ENTRY_INDEX_OUT_OF_RANGE = 12;
287
288    // Errors for dictionary names.
289    DICTIONARY_NAME_EMPTY = 13;
290    DICTIONARY_NAME_TOO_LONG = 14;
291    DICTIONARY_NAME_CONTAINS_INVALID_CHARACTER = 15;
292    DICTIONARY_NAME_DUPLICATED = 16;
293
294    // Errors for entry data.
295    READING_EMPTY = 17;
296    READING_TOO_LONG = 18;
297    READING_CONTAINS_INVALID_CHARACTER = 19;
298    WORD_EMPTY = 20;
299    WORD_TOO_LONG = 21;
300    WORD_CONTAINS_INVALID_CHARACTER = 22;
301    INVALID_POS_TYPE = 23;
302    COMMENT_TOO_LONG = 24;
303    COMMENT_CONTAINS_INVALID_CHARACTER = 25;
304
305    // Errors for importing.
306    IMPORT_TOO_MANY_WORDS = 26;
307    IMPORT_INVALID_ENTRIES = 27;
308
309    NO_UNDO_HISTORY = 28;
310  };
311
312  required Status status = 1;
313  optional uint64 session_id = 2;
314  optional UserDictionaryStorage storage = 3;
315  // Use entries field instead.
316  reserved 4;  // Deprecated entry
317  optional uint64 dictionary_id = 5;
318  optional uint32 entry_size = 6;
319  repeated UserDictionary.Entry entries = 7;
320};
321