Embed dictionary and connection data as one file
This CL introduces a new IMY file, mozc.imy, that contains all the data
set necessary for Mozc engine. Thus, system.dictionary.imy and
connection.data.imy are replaced by mozc.imy.
To this end, two build macros, MOZC_USE_SEPARATE_CONNECTION_DATA and
MOZC_USE_SEPARATE_DICTIONARY are merged into MOZC_USE_SEPARATE_DATASET.
BUG=
TEST=
REF_BUG=26841123
REF_CL=114073240
REF_TIME=2016-02-08T11:24:27+09:00
REF_TIME_RAW=1454898267 +0900
Noriyuki Takahashi
8 years ago
205 | 205 | 'target_name': 'assets', |
206 | 206 | 'type': 'none', |
207 | 207 | 'dependencies': [ |
208 | 'assets_connection_data', | |
209 | 208 | 'assets_credits', |
210 | 'assets_dictionary', | |
209 | 'assets_mozc_dataset', | |
211 | 210 | 'assets_touch_stat_data', |
212 | 211 | ] |
213 | 212 | }, |
223 | 222 | }], |
224 | 223 | }, |
225 | 224 | { |
226 | 'target_name': 'assets_connection_data', | |
225 | 'target_name': 'assets_mozc_dataset', | |
227 | 226 | 'type': 'none', |
228 | 227 | 'conditions': [ |
229 | ['use_separate_connection_data==1', | |
228 | ['use_separate_dataset==1', | |
230 | 229 | { |
231 | 230 | 'actions': [ |
232 | 231 | { |
233 | 'action_name': 'assets_copy_connection_data', | |
232 | 'action_name': 'assets_copy_dataset', | |
234 | 233 | 'inputs': [ |
235 | '<(connection_data)', | |
234 | '<(mozc_dataset)', | |
236 | 235 | ], |
237 | 236 | 'outputs': [ |
238 | '<(sdk_asset_dir)/connection.data.imy', | |
239 | ], | |
240 | 'action': [ | |
241 | # Note that multiple output files cannot be handled | |
242 | # by copy_file script. | |
243 | '<@(copy_file)', '<@(_inputs)', '<@(_outputs)', | |
244 | ], | |
245 | }, | |
246 | ], | |
247 | }, | |
248 | ], | |
249 | ], | |
250 | }, | |
251 | { | |
252 | 'target_name': 'assets_dictionary', | |
253 | 'type': 'none', | |
254 | 'conditions': [ | |
255 | ['use_separate_dictionary==1', | |
256 | { | |
257 | 'actions': [ | |
258 | { | |
259 | 'action_name': 'assets_copy_dictionary', | |
260 | 'inputs': [ | |
261 | '<(dictionary_data)' | |
262 | ], | |
263 | 'outputs': [ | |
264 | '<(sdk_asset_dir)/system.dictionary.imy', | |
237 | '<(sdk_asset_dir)/mozc.imy', | |
265 | 238 | ], |
266 | 239 | 'action': [ |
267 | 240 | # Note that multiple output files cannot be handled |
646 | 619 | 'action': [ |
647 | 620 | 'python', 'run_android_test.py', |
648 | 621 | '--android_home=<(android_home)', |
649 | '--mozc_connection_data_file=<(connection_data)', | |
650 | 622 | '--mozc_connection_text_data_file=<(connection_text_data)', |
651 | 623 | '--mozc_data_dir=<(mozc_data_dir)', |
652 | '--mozc_dictionary_data_file=<(dictionary_data)', | |
653 | '--mozc_test_connection_data_file=<(test_connection_data)', | |
624 | '--mozc_dataset_file=<(mozc_dataset)', | |
625 | '--mozc_test_dataset_file=<(test_mozc_dataset)', | |
654 | 626 | '--mozc_test_connection_text_data_file=<(test_connection_text_data)', |
655 | 627 | '--native_abi=<(abi)', |
656 | 628 | '--output_report_dir=<(test_report_dir)', |
51 | 51 | '<(android_home)/extras/android/support/v13/android-support-v13.jar', |
52 | 52 | ], |
53 | 53 | 'shared_intermediate_mozc_dir': '<(SHARED_INTERMEDIATE_DIR)/', |
54 | 'test_connection_data': '<(shared_intermediate_mozc_dir)/data_manager/testing/connection.data', | |
54 | 'test_mozc_dataset': '<(shared_intermediate_mozc_dir)/data_manager/testing/mock_mozc.data', | |
55 | 55 | 'test_connection_text_data': '<(shared_intermediate_mozc_dir)/data_manager/testing/connection_single_column.txt', |
56 | 56 | # e.g. xxxx/out_android/gtest_report |
57 | 57 | 'test_report_dir': '<(SHARED_INTERMEDIATE_DIR)/../../gtest_report', |
74 | 74 | # and Fedora (jsr-305.jar). |
75 | 75 | # TODO(yukawa): We should not rely on "find" command here. |
76 | 76 | 'jsr305_jar_path': '<!(find /usr/share/java -name "jsr305.jar" -o -name "jsr-305.jar")', |
77 | 'dictionary_data': '<(shared_intermediate_mozc_dir)/data_manager/oss/system.dictionary', | |
78 | 'connection_data': '<(shared_intermediate_mozc_dir)/data_manager/oss/connection.data', | |
77 | 'mozc_dataset': '<(shared_intermediate_mozc_dir)/data_manager/oss/mozc.imy', | |
79 | 78 | 'connection_text_data': '<(shared_intermediate_mozc_dir)/data_manager/oss/connection_single_column.txt', |
80 | 79 | 'native_test_small_targets': [ |
81 | 80 | 'oss_data_manager_test', |
54 | 54 | namespace mozc { |
55 | 55 | namespace jni { |
56 | 56 | namespace { |
57 | jobject g_connection_data_buffer; | |
58 | jobject g_dictionary_buffer; | |
57 | jobject g_mozc_data_buffer; | |
59 | 58 | |
60 | 59 | // Returns a job setting for usage stats job. |
61 | 60 | const Scheduler::JobSetting GetJobSetting() { |
91 | 90 | DISALLOW_COPY_AND_ASSIGN(SessionHandlerSingletonAdapter); |
92 | 91 | }; |
93 | 92 | |
94 | void Initialize( | |
95 | JavaVM *vm, | |
96 | const char *user_profile_directory, | |
97 | void *dictionary_address, int dictionary_size, | |
98 | void *connection_data_address, int connection_data_size) { | |
93 | void Initialize(JavaVM *vm, const char *user_profile_directory, | |
94 | void *mozc_data_address, int mozc_data_size) { | |
99 | 95 | // First of all, set the user profile directory. |
100 | 96 | SystemUtil::SetUserProfileDirectory(user_profile_directory); |
101 | 97 | |
102 | // Initialize Java native callback proxy. | |
98 | // Initializes Java native callback proxy. | |
103 | 99 | JavaHttpClientProxy::SetJavaVM(vm); |
104 | 100 | |
105 | // Initialize dictionary data. | |
106 | DataManagerType::SetDictionaryData(dictionary_address, dictionary_size); | |
107 | DataManagerType::SetConnectionData(connection_data_address, | |
108 | connection_data_size); | |
101 | // Initializes mozc data. | |
102 | DataManagerType::SetMozcDataSet(mozc_data_address, mozc_data_size); | |
109 | 103 | |
110 | 104 | mozc::Singleton<SessionHandlerSingletonAdapter>::get()->getHandler() |
111 | 105 | ->AddObserver(Singleton<session::SessionUsageObserver>::get()); |
112 | 106 | |
113 | // Start usage stats timer. | |
107 | // Starts usage stats timer. | |
114 | 108 | mozc::Scheduler::AddJob(GetJobSetting()); |
115 | 109 | } |
116 | 110 | |
142 | 136 | void JNICALL onPostLoad(JNIEnv *env, |
143 | 137 | jclass clazz, |
144 | 138 | jstring user_profile_directory_path, |
145 | jobject dictionary_buffer, | |
146 | jobject connection_data_buffer) { | |
147 | // Keep the global references of the buffers. | |
148 | g_dictionary_buffer = env->NewGlobalRef(dictionary_buffer); | |
149 | g_connection_data_buffer = env->NewGlobalRef(connection_data_buffer); | |
139 | jobject mozc_data_buffer) { | |
140 | // Keep the global references of the buffer. | |
141 | g_mozc_data_buffer = env->NewGlobalRef(mozc_data_buffer); | |
150 | 142 | |
151 | 143 | const char *utf8_user_profile_directory_path = |
152 | 144 | env->GetStringUTFChars(user_profile_directory_path, nullptr); |
154 | 146 | JavaVM *vm = NULL; |
155 | 147 | env->GetJavaVM(&vm); |
156 | 148 | |
157 | Initialize( | |
158 | vm, utf8_user_profile_directory_path, | |
159 | env->GetDirectBufferAddress(dictionary_buffer), | |
160 | env->GetDirectBufferCapacity(dictionary_buffer), | |
161 | env->GetDirectBufferAddress(connection_data_buffer), | |
162 | env->GetDirectBufferCapacity(connection_data_buffer)); | |
149 | Initialize(vm, utf8_user_profile_directory_path, | |
150 | env->GetDirectBufferAddress(mozc_data_buffer), | |
151 | env->GetDirectBufferCapacity(mozc_data_buffer)); | |
163 | 152 | env->ReleaseStringUTFChars(user_profile_directory_path, |
164 | 153 | utf8_user_profile_directory_path); |
165 | 154 | } |
197 | 186 | "([B)[B", |
198 | 187 | reinterpret_cast<void*>(&mozc::jni::evalCommand)}, |
199 | 188 | {"onPostLoad", |
200 | "(Ljava/lang/String;Ljava/nio/Buffer;Ljava/nio/Buffer;)V", | |
189 | "(Ljava/lang/String;Ljava/nio/Buffer;)V", | |
201 | 190 | reinterpret_cast<void*>(&mozc::jni::onPostLoad)}, |
202 | 191 | {"getVersion", |
203 | 192 | "()Ljava/lang/String;", |
225 | 214 | // Delete global references. |
226 | 215 | JNIEnv *env = mozc::AndroidUtil::GetEnv(vm); |
227 | 216 | if (env) { |
228 | env->DeleteGlobalRef(mozc::jni::g_connection_data_buffer); | |
229 | env->DeleteGlobalRef(mozc::jni::g_dictionary_buffer); | |
217 | env->DeleteGlobalRef(mozc::jni::g_mozc_data_buffer); | |
230 | 218 | } |
231 | 219 | } |
232 | 220 | } // extern "C" |
103 | 103 | help='[NATIVE] Limits testcases to run.') |
104 | 104 | parser.add_option('--native_abi', dest='abi', default='armeabi', |
105 | 105 | help='[JAVA][NATIVE] ABI of built test executables.') |
106 | parser.add_option('--mozc_dictionary_data_file', | |
107 | dest='mozc_dictionary_data_file', default=None, | |
108 | help='[NATIVE] Path to system.dictionary file.') | |
109 | parser.add_option('--mozc_connection_data_file', | |
110 | dest='mozc_connection_data_file', default=None, | |
111 | help='[NATIVE] Path to connection.data file.') | |
106 | parser.add_option('--mozc_dataset_file', | |
107 | dest='mozc_dataset_file', default=None, | |
108 | help='[NATIVE] Path to mozc.data file.') | |
112 | 109 | parser.add_option('--mozc_connection_text_data_file', |
113 | 110 | dest='mozc_connection_text_data_file', default=None, |
114 | 111 | help='[NATIVE] Path to connection_single_column.txt file.') |
115 | parser.add_option('--mozc_test_connection_data_file', | |
116 | dest='mozc_test_connection_data_file', default=None, | |
117 | help='[NATIVE] Path to test_connection.data file.') | |
112 | parser.add_option('--mozc_test_dataset_file', | |
113 | dest='mozc_test_dataset_file', default=None, | |
114 | help='[NATIVE] Path to mock_mozc.data file.') | |
118 | 115 | parser.add_option('--mozc_test_connection_text_data_file', |
119 | 116 | dest='mozc_test_connection_text_data_file', default=None, |
120 | 117 | help='[NATIVE] Path to connection_single_column.txt file.') |
276 | 273 | self._RunCommand('rm', remote_report_path) |
277 | 274 | |
278 | 275 | def SetUpTest(self, device, mount_point, remote_dir, |
279 | dictionary_data, connection_data, connection_text_data, | |
280 | test_connection_data, test_connection_text_data, | |
276 | mozc_dataset, connection_text_data, | |
277 | test_dataset, test_connection_text_data, | |
281 | 278 | mozc_data_dir): |
282 | 279 | """Set up the android to run tests.""" |
283 | 280 | self.WaitForMount() |
291 | 288 | # data is set at jni loading time, but it is necessary to somehow |
292 | 289 | # set the data in native tests. So, copy the dictionary data to the |
293 | 290 | # emulator. |
294 | self.CopyFile(host_path=dictionary_data, | |
291 | self.CopyFile(host_path=mozc_dataset, | |
295 | 292 | remote_path=os.path.join(remote_dir, |
296 | 'embedded_data', 'dictionary_data'), | |
297 | operation='push') | |
298 | self.CopyFile(host_path=connection_data, | |
299 | remote_path=os.path.join(remote_dir, | |
300 | 'embedded_data', 'connection_data'), | |
293 | 'embedded_data', 'mozc_data'), | |
301 | 294 | operation='push') |
302 | 295 | self.CopyFile(host_path=connection_text_data, |
303 | 296 | remote_path=os.path.join(remote_dir, |
304 | 297 | 'data_manager', 'android', |
305 | 298 | 'connection_single_column.txt'), |
306 | 299 | operation='push') |
307 | self.CopyFile(host_path=test_connection_data, | |
300 | self.CopyFile(host_path=test_dataset, | |
308 | 301 | remote_path=os.path.join(remote_dir, |
309 | 302 | 'data_manager', 'testing', |
310 | 'connection_data.data'), | |
303 | 'mock_mozc.data'), | |
311 | 304 | operation='push') |
312 | 305 | self.CopyFile(host_path=test_connection_text_data, |
313 | 306 | remote_path=os.path.join(remote_dir, |
338 | 331 | error_messages = [] |
339 | 332 | self.SetUpTest(options.remote_device, options.remote_mount_point, |
340 | 333 | options.remote_dir, |
341 | options.mozc_dictionary_data_file, | |
342 | options.mozc_connection_data_file, | |
334 | options.mozc_dataset_file, | |
343 | 335 | options.mozc_connection_text_data_file, |
344 | options.mozc_test_connection_data_file, | |
336 | options.mozc_test_dataset_file, | |
345 | 337 | options.mozc_test_connection_text_data_file, |
346 | 338 | options.mozc_data_dir) |
347 | 339 | if options.testcase: |
+5
-9
55 | 55 | // The file name of the system dictionary and connection data file in the apk. |
56 | 56 | // This is determined in build.xml. |
57 | 57 | // ".imy" extentions expects the the entry is uncompressed. |
58 | private static final String DICTIONARY_FILE_NAME = "assets/system.dictionary.imy"; | |
59 | private static final String CONNECTION_DATA_FILE_NAME = "assets/connection.data.imy"; | |
58 | private static final String DATASET_FILE_NAME = "assets/mozc.imy"; | |
60 | 59 | |
61 | 60 | @Override |
62 | 61 | public void initialize(Context context) { |
76 | 75 | } |
77 | 76 | } |
78 | 77 | |
79 | // Get buffers for the dictionary from the raw .apk file. | |
78 | // Get a buffer for the dictionary from the raw .apk file. | |
80 | 79 | ZipFile zipfile = new ZipFile(info.sourceDir); |
81 | Buffer dictionaryBuffer = | |
82 | ZipFileUtil.getBuffer(zipfile, DICTIONARY_FILE_NAME); | |
83 | Buffer connectionDataBuffer = | |
84 | ZipFileUtil.getBuffer(zipfile, CONNECTION_DATA_FILE_NAME); | |
80 | Buffer dataSetBuffer = | |
81 | ZipFileUtil.getBuffer(zipfile, DATASET_FILE_NAME); | |
85 | 82 | |
86 | 83 | // Get Java package's version name, to check the version consistency with libmozc.so |
87 | 84 | // Note that obtained version name is suffixed by android architecture (e.g., -arm). |
93 | 90 | } |
94 | 91 | |
95 | 92 | // Load the shared object. |
96 | MozcJNI.load(userProfileDirectory.getAbsolutePath(), | |
97 | dictionaryBuffer, connectionDataBuffer, matcher.group(1)); | |
93 | MozcJNI.load(userProfileDirectory.getAbsolutePath(), dataSetBuffer, matcher.group(1)); | |
98 | 94 | } catch (IOException e) { |
99 | 95 | MozcLog.e("Failed to load system dictionary.", e); |
100 | 96 | throw new RuntimeException(e); |
46 | 46 | /** |
47 | 47 | * Loads and initializes the JNI library. |
48 | 48 | * |
49 | * @param dictionaryBuffer the buffer pointing the system dictionary | |
50 | * @param connectionDataBuffer the buffer pointing the connection data | |
49 | * @param mozcDataBuffer the buffer pointing to the mozc data (model, dictionary, etc.) | |
51 | 50 | * @param expectedVersion expected version name of .so |
52 | 51 | */ |
53 | 52 | static void load( |
54 | String userProfileDirectoryPath, Buffer dictionaryBuffer, Buffer connectionDataBuffer, | |
55 | String expectedVersion) { | |
53 | String userProfileDirectoryPath, Buffer mozcDataBuffer, String expectedVersion) { | |
56 | 54 | Preconditions.checkNotNull(userProfileDirectoryPath); |
57 | Preconditions.checkNotNull(dictionaryBuffer); | |
58 | Preconditions.checkNotNull(connectionDataBuffer); | |
55 | Preconditions.checkNotNull(mozcDataBuffer); | |
59 | 56 | Preconditions.checkNotNull(expectedVersion); |
60 | 57 | |
61 | 58 | if (isLoaded) { |
80 | 77 | message.append(" Server:").append(nativeVersion); |
81 | 78 | throw new UnsatisfiedLinkError(message.toString()); |
82 | 79 | } |
83 | onPostLoad(userProfileDirectoryPath, dictionaryBuffer, connectionDataBuffer); | |
80 | onPostLoad(userProfileDirectoryPath, mozcDataBuffer); | |
84 | 81 | isLoaded = true; |
85 | 82 | MozcLog.d("end MozcJNI#load " + System.nanoTime()); |
86 | 83 | } |
103 | 100 | * of dictionary data from Java as only Java knows where the data is in our context. |
104 | 101 | */ |
105 | 102 | private static synchronized native void onPostLoad( |
106 | String userProfileDirectoryPath, Buffer dictionaryData, Buffer connectionData); | |
103 | String userProfileDirectoryPath, Buffer mozcDataBuffer); | |
107 | 104 | |
108 | 105 | /** |
109 | 106 | * @return Version string of shared object |
811 | 811 | # Dictionary configuration |
812 | 812 | if target_platform == 'Android': |
813 | 813 | gyp_options.extend(['-D', 'dictionary=small']) |
814 | gyp_options.extend(['-D', 'use_separate_collocation_data=0']) | |
815 | gyp_options.extend(['-D', 'use_separate_connection_data=1']) | |
816 | gyp_options.extend(['-D', 'use_separate_dictionary=1']) | |
814 | gyp_options.extend(['-D', 'use_separate_dataset=1']) | |
817 | 815 | gyp_options.extend(['-D', 'use_1byte_cost_for_connection_data=1']) |
818 | 816 | gyp_options.extend(['-D', 'use_packed_dictionary=0']) |
819 | 817 | elif target_platform == 'NaCl': |
820 | 818 | gyp_options.extend(['-D', 'dictionary=desktop']) |
821 | gyp_options.extend(['-D', 'use_separate_collocation_data=0']) | |
822 | gyp_options.extend(['-D', 'use_separate_connection_data=0']) | |
823 | gyp_options.extend(['-D', 'use_separate_dictionary=0']) | |
819 | gyp_options.extend(['-D', 'use_separate_dataset=0']) | |
824 | 820 | gyp_options.extend(['-D', 'use_1byte_cost_for_connection_data=0']) |
825 | 821 | gyp_options.extend(['-D', 'use_packed_dictionary=1']) |
826 | 822 | else: |
827 | 823 | gyp_options.extend(['-D', 'dictionary=desktop']) |
828 | gyp_options.extend(['-D', 'use_separate_collocation_data=0']) | |
829 | gyp_options.extend(['-D', 'use_separate_connection_data=0']) | |
830 | gyp_options.extend(['-D', 'use_separate_dictionary=0']) | |
824 | gyp_options.extend(['-D', 'use_separate_dataset=0']) | |
831 | 825 | gyp_options.extend(['-D', 'use_1byte_cost_for_connection_data=0']) |
832 | 826 | gyp_options.extend(['-D', 'use_packed_dictionary=0']) |
833 | 827 |
192 | 192 | 'type': 'none', |
193 | 193 | 'toolsets': ['host'], |
194 | 194 | 'conditions': [ |
195 | ['use_separate_dictionary==1',{ | |
195 | ['use_separate_dataset==1',{ | |
196 | 196 | 'dependencies': [ |
197 | 197 | 'gen_separate_dictionary_data_for_<(dataset_tag)#host', |
198 | 198 | ], |
210 | 210 | 'type': 'none', |
211 | 211 | 'toolsets': ['host'], |
212 | 212 | 'conditions': [ |
213 | ['use_separate_connection_data==1',{ | |
213 | ['use_separate_dataset==1',{ | |
214 | 214 | 'dependencies': [ |
215 | 215 | 'gen_separate_connection_data_for_<(dataset_tag)#host', |
216 | 216 | ], |
28 | 28 | |
29 | 29 | #include "data_manager/oss/oss_data_manager.h" |
30 | 30 | |
31 | #include "base/embedded_file.h" | |
31 | 32 | #include "base/logging.h" |
32 | 33 | #include "base/port.h" |
33 | 34 | #include "converter/boundary_struct.h" |
43 | 44 | |
44 | 45 | namespace mozc { |
45 | 46 | namespace oss { |
46 | ||
47 | namespace { | |
47 | namespace { | |
48 | ||
49 | const char *g_mozc_data_address = nullptr; | |
50 | size_t g_mozc_data_size = 0; | |
51 | ||
52 | #ifdef MOZC_USE_SEPARATE_DATASET | |
53 | const EmbeddedFile kOssMozcDataSet = {nullptr, 0}; | |
54 | #else | |
55 | // kOssMozcDataSet is embedded. | |
56 | #include "data_manager/oss/mozc_imy.h" | |
57 | #endif // MOZC_USE_SEPARATE_DATASET | |
58 | ||
59 | #ifndef MOZC_DATASET_MAGIC_NUMBER | |
60 | #error "MOZC_DATASET_MAGIC_NUMBER is not defined by build system" | |
61 | #endif // MOZC_DATASET_MAGIC_NUMBER | |
62 | ||
63 | const char kMagicNumber[] = MOZC_DATASET_MAGIC_NUMBER; | |
64 | ||
48 | 65 | // kLidGroup[] is defined in the following automatically generated header file. |
49 | 66 | #include "data_manager/oss/pos_group_data.h" |
50 | } // namespace | |
67 | ||
68 | } // namespace | |
69 | ||
70 | OssDataManager::OssDataManager() { | |
71 | const StringPiece magic(kMagicNumber, arraysize(kMagicNumber) - 1); | |
72 | if (g_mozc_data_address != nullptr) { | |
73 | const StringPiece data(g_mozc_data_address, g_mozc_data_size); | |
74 | CHECK(manager_.InitFromArray(data, magic)) | |
75 | << "Image set by SetMozcDataSet() is broken"; | |
76 | return; | |
77 | } | |
78 | #ifdef MOZC_USE_SEPARATE_DATASET | |
79 | LOG(FATAL) | |
80 | << "When MOZC_USE_SEPARATE_DATASET build flag is defined, " | |
81 | << "OssDataManager::SetMozcDataSet() must be called before " | |
82 | << "instantiation of OssDataManager instances."; | |
83 | #endif // MOZC_USE_SEPARATE_DATASET | |
84 | CHECK(manager_.InitFromArray(LoadEmbeddedFile(kOssMozcDataSet), magic)) | |
85 | << "Embedded mozc_imy.h for OSS is broken"; | |
86 | } | |
87 | ||
88 | OssDataManager::~OssDataManager() = default; | |
51 | 89 | |
52 | 90 | const uint8 *OssDataManager::GetPosGroupData() const { |
53 | 91 | DCHECK(kLidGroup != NULL); |
54 | 92 | return kLidGroup; |
55 | 93 | } |
56 | 94 | |
57 | namespace { | |
58 | #ifdef MOZC_USE_SEPARATE_CONNECTION_DATA | |
59 | const char *kConnectionData_data = NULL; | |
60 | const size_t kConnectionData_size = 0; | |
61 | #else // MOZC_USE_SEPARATE_CONNECTION_DATA | |
62 | // Automatically generated header containing the definitions of | |
63 | // kConnectionData_data and kConnectionData_size. We don't embed it when | |
64 | // connection data is supplied from outside. | |
65 | #include "data_manager/oss/embedded_connection_data.h" | |
66 | #endif // MOZC_USE_SEPARATE_CONNECTION_DATA | |
67 | ||
68 | char *g_connection_data_address = const_cast<char *>(kConnectionData_data); | |
69 | int g_connection_data_size = kConnectionData_size; | |
70 | } // namespace | |
71 | ||
72 | #ifdef MOZC_USE_SEPARATE_CONNECTION_DATA | |
73 | void OssDataManager::SetConnectionData(void *address, size_t size) { | |
74 | g_connection_data_address = reinterpret_cast<char *>(address); | |
75 | g_connection_data_size = size; | |
76 | DCHECK(g_connection_data_address); | |
77 | DCHECK_GT(g_connection_data_size, 0); | |
78 | } | |
79 | #endif // MOZC_USE_SEPARATE_CONNECTION_DATA | |
95 | // Both pointers can be nullptr when the DataManager is reset on testing. | |
96 | void OssDataManager::SetMozcDataSet(void *address, size_t size) { | |
97 | g_mozc_data_address = reinterpret_cast<char *>(address); | |
98 | g_mozc_data_size = size; | |
99 | } | |
80 | 100 | |
81 | 101 | void OssDataManager::GetConnectorData(const char **data, size_t *size) const { |
82 | #ifdef MOZC_USE_SEPARATE_CONNECTION_DATA | |
83 | if (!g_connection_data_address || g_connection_data_size == 0) { | |
84 | LOG(FATAL) << "Connection data is not yet set."; | |
85 | CHECK(false); | |
86 | } | |
87 | #endif | |
88 | *data = g_connection_data_address; | |
89 | *size = g_connection_data_size; | |
90 | } | |
91 | ||
92 | namespace { | |
93 | #ifdef MOZC_USE_SEPARATE_DICTIONARY | |
94 | const char *kDictionaryData_data = NULL; | |
95 | const size_t kDictionaryData_size = 0; | |
96 | #else // MOZC_USE_SEPARATE_DICTIONARY | |
97 | // Automatically generated header containing the definitions of | |
98 | // kDictionaryData_data[] and kDictionaryData_size. | |
99 | #include "data_manager/oss/embedded_dictionary_data.h" | |
100 | #endif // MOZC_USE_SEPARATE_DICTIONARY | |
101 | ||
102 | char *g_dictionary_address = const_cast<char *>(kDictionaryData_data); | |
103 | int g_dictionary_size = kDictionaryData_size; | |
104 | } // namespace | |
102 | manager_.GetConnectorData(data, size); | |
103 | } | |
105 | 104 | |
106 | 105 | void OssDataManager::GetSystemDictionaryData( |
107 | 106 | const char **data, int *size) const { |
108 | *data = g_dictionary_address; | |
109 | *size = g_dictionary_size; | |
110 | } | |
111 | ||
112 | #ifdef MOZC_USE_SEPARATE_DICTIONARY | |
113 | void OssDataManager::SetDictionaryData(void *address, size_t size) { | |
114 | g_dictionary_address = reinterpret_cast<char *>(address); | |
115 | g_dictionary_size = size; | |
116 | DCHECK(g_dictionary_address); | |
117 | DCHECK_GT(g_dictionary_size, 0); | |
118 | } | |
119 | #endif // MOZC_USE_SEPARATE_DICTIONARY | |
107 | manager_.GetSystemDictionaryData(data, size); | |
108 | } | |
120 | 109 | |
121 | 110 | namespace { |
122 | 111 | // Automatically generated headers containing data set for segmenter. |
161 | 150 | *size = arraysize(kReadingCorrections); |
162 | 151 | } |
163 | 152 | |
164 | namespace { | |
165 | #ifdef MOZC_USE_SEPARATE_COLLOCATION_DATA | |
166 | namespace CollocationData { | |
167 | const char *kExistenceFilter_data = NULL; | |
168 | const size_t kExistenceFilter_size = 0; | |
169 | } // namespace CollocationData | |
170 | #else // MOZC_USE_SEPARATE_COLLOCATION_DATA | |
171 | // Include CollocationData::kExistenceFilter_data and | |
172 | // CollocationData::kExistenceFilter_size. | |
173 | #include "data_manager/oss/embedded_collocation_data.h" | |
174 | #endif // MOZC_USE_SEPARATE_COLLOCATION_DATA | |
175 | ||
176 | char *g_collocation_data_address = | |
177 | const_cast<char *>(CollocationData::kExistenceFilter_data); | |
178 | int g_collocation_data_size = CollocationData::kExistenceFilter_size; | |
179 | ||
180 | // Include CollocationSuppressionData::kExistenceFilter_data and | |
181 | // CollocationSuppressionData::kExistenceFilter_size. | |
182 | #include "data_manager/oss/embedded_collocation_suppression_data.h" | |
183 | } // namespace | |
184 | ||
185 | #ifdef MOZC_USE_SEPARATE_COLLOCATION_DATA | |
186 | void OssDataManager::SetCollocationData(void *address, size_t size) { | |
187 | g_collocation_data_address = reinterpret_cast<char *>(address); | |
188 | g_collocation_data_size = size; | |
189 | DCHECK(g_collocation_data_address); | |
190 | DCHECK_GT(g_collocation_data_size, 0); | |
191 | } | |
192 | #endif // MOZC_USE_SEPARATE_COLLOCATION_DATA | |
193 | ||
194 | 153 | void OssDataManager::GetCollocationData(const char **array, |
195 | 154 | size_t *size) const { |
196 | #ifdef MOZC_USE_SEPARATE_COLLOCATION_DATA | |
197 | if (!g_collocation_data_address || g_collocation_data_size == 0) { | |
198 | LOG(FATAL) << "Collocation data is not yet set."; | |
199 | } | |
200 | #endif // MOZC_USE_SEPARATE_COLLOCATION_DATA | |
201 | *array = g_collocation_data_address; | |
202 | *size = g_collocation_data_size; | |
155 | manager_.GetCollocationData(array, size); | |
203 | 156 | } |
204 | 157 | |
205 | 158 | void OssDataManager::GetCollocationSuppressionData(const char **array, |
206 | 159 | size_t *size) const { |
207 | *array = CollocationSuppressionData::kExistenceFilter_data; | |
208 | *size = CollocationSuppressionData::kExistenceFilter_size; | |
209 | } | |
210 | ||
211 | namespace { | |
212 | // Include kSuggestionFilterData_data and kSuggestionFilterData_size. | |
213 | #include "data_manager/oss/suggestion_filter_data.h" | |
214 | } // namespace | |
160 | manager_.GetCollocationSuppressionData(array, size); | |
161 | } | |
215 | 162 | |
216 | 163 | void OssDataManager::GetSuggestionFilterData(const char **data, |
217 | 164 | size_t *size) const { |
218 | *data = kSuggestionFilterData_data; | |
219 | *size = kSuggestionFilterData_size; | |
165 | manager_.GetSuggestionFilterData(data, size); | |
220 | 166 | } |
221 | 167 | |
222 | 168 | namespace { |
53 | 53 | '<(platform_data_dir)/reading_correction.tsv', |
54 | 54 | ], |
55 | 55 | 'gen_test_dictionary': 'false', |
56 | # Hex-escaped string of "\xEFG\0\0gleJaIME\r\n" | |
57 | 'magic_number': '\\xEF\\x47\\x00\\x00\\x67\\x6C\\x65\\x4A\\x61\\x49\\x4D\\x45\\x0D\\x0A', | |
56 | # Hex-escaped string of "\xEFMOZC\r\n" | |
57 | 'magic_number': "\\xEF\\x4D\\x4F\\x5A\\x43\\x0D\\x0A", | |
58 | 58 | 'mozc_data_varname': 'kOssMozcDataSet', |
59 | 'out_mozc_data': 'oss_mozc.data', | |
60 | 'out_mozc_data_header': 'oss_mozc_data.h', | |
59 | 'out_mozc_data': 'mozc.imy', | |
60 | 'out_mozc_data_header': 'mozc_imy.h', | |
61 | 61 | }, |
62 | 62 | # This 'includes' defines the following targets: |
63 | 63 | # - oss_data_manager (type: static_library) |
30 | 30 | #define MOZC_DATA_MANAGER_OSS_OSS_DATA_MANAGER_H_ |
31 | 31 | |
32 | 32 | #include "base/port.h" |
33 | #include "data_manager/data_manager.h" | |
33 | 34 | #include "data_manager/oss/oss_user_pos_manager.h" |
34 | 35 | |
35 | 36 | namespace mozc { |
37 | 38 | |
38 | 39 | class OssDataManager : public OssUserPosManager { |
39 | 40 | public: |
40 | OssDataManager() {} | |
41 | virtual ~OssDataManager() {} | |
41 | OssDataManager(); | |
42 | ~OssDataManager() override; | |
42 | 43 | |
43 | #ifdef MOZC_USE_SEPARATE_COLLOCATION_DATA | |
44 | static void SetCollocationData(void *address, size_t size); | |
45 | #endif // MOZC_USE_SEPARATE_COLLOCATION_DATA | |
46 | #ifdef MOZC_USE_SEPARATE_CONNECTION_DATA | |
47 | static void SetConnectionData(void *address, size_t size); | |
48 | #endif // MOZC_USE_SEPARATE_CONNECTION_DATA | |
49 | #ifdef MOZC_USE_SEPARATE_DICTIONARY | |
50 | static void SetDictionaryData(void *address, size_t size); | |
51 | #endif // MOZC_USE_SEPARATE_DICTIONARY | |
44 | static void SetMozcDataSet(void *address, size_t size); | |
52 | 45 | |
53 | virtual const uint8 *GetPosGroupData() const; | |
54 | virtual void GetConnectorData(const char **data, size_t *size) const; | |
55 | virtual void GetSegmenterData( | |
56 | size_t *l_num_elements, size_t *r_num_elements, | |
57 | const uint16 **l_table, const uint16 **r_table, | |
58 | size_t *bitarray_num_bytes, const char **bitarray_data, | |
59 | const BoundaryData **boundary_data) const; | |
60 | virtual void GetSystemDictionaryData(const char **data, int *size) const; | |
61 | virtual void GetSuffixDictionaryData(const dictionary::SuffixToken **tokens, | |
62 | size_t *size) const; | |
63 | virtual void GetReadingCorrectionData(const ReadingCorrectionItem **array, | |
64 | size_t *size) const; | |
65 | virtual void GetCollocationData(const char **array, size_t *size) const; | |
66 | virtual void GetCollocationSuppressionData(const char **array, | |
67 | size_t *size) const; | |
68 | virtual void GetSuggestionFilterData(const char **data, size_t *size) const; | |
69 | virtual void GetSymbolRewriterData(const EmbeddedDictionary::Token **data, | |
70 | size_t *size) const; | |
46 | const uint8 *GetPosGroupData() const override; | |
47 | void GetConnectorData(const char **data, size_t *size) const override; | |
48 | void GetSegmenterData(size_t *l_num_elements, size_t *r_num_elements, | |
49 | const uint16 **l_table, const uint16 **r_table, | |
50 | size_t *bitarray_num_bytes, const char **bitarray_data, | |
51 | const BoundaryData **boundary_data) const override; | |
52 | void GetSystemDictionaryData(const char **data, int *size) const override; | |
53 | void GetSuffixDictionaryData(const dictionary::SuffixToken **tokens, | |
54 | size_t *size) const override; | |
55 | void GetReadingCorrectionData(const ReadingCorrectionItem **array, | |
56 | size_t *size) const override; | |
57 | void GetCollocationData(const char **array, size_t *size) const override; | |
58 | void GetCollocationSuppressionData(const char **array, | |
59 | size_t *size) const override; | |
60 | void GetSuggestionFilterData(const char **data, size_t *size) const override; | |
61 | void GetSymbolRewriterData(const EmbeddedDictionary::Token **data, | |
62 | size_t *size) const override; | |
71 | 63 | #ifndef NO_USAGE_REWRITER |
72 | virtual void GetUsageRewriterData( | |
64 | void GetUsageRewriterData( | |
73 | 65 | const ConjugationSuffix **base_conjugation_suffix, |
74 | 66 | const ConjugationSuffix **conjugation_suffix_data, |
75 | 67 | const int **conjugation_suffix_data_index, |
76 | const UsageDictItem **usage_data_value) const; | |
68 | const UsageDictItem **usage_data_value) const override; | |
77 | 69 | #endif // NO_USAGE_REWRITER |
78 | virtual void GetCounterSuffixSortedArray(const CounterSuffixEntry **array, | |
79 | size_t *size) const; | |
70 | void GetCounterSuffixSortedArray(const CounterSuffixEntry **array, | |
71 | size_t *size) const override; | |
80 | 72 | |
81 | 73 | private: |
74 | DataManager manager_; | |
82 | 75 | DISALLOW_COPY_AND_ASSIGN(OssDataManager); |
83 | 76 | }; |
84 | 77 |
575 | 575 | '<@(linux_ldflags)', |
576 | 576 | ], |
577 | 577 | }], |
578 | ['use_separate_collocation_data==1', { | |
579 | 'defines': ['MOZC_USE_SEPARATE_COLLOCATION_DATA'], | |
580 | }], | |
581 | ['use_separate_connection_data==1', { | |
582 | 'defines': ['MOZC_USE_SEPARATE_CONNECTION_DATA'], | |
583 | }], | |
584 | ['use_separate_dictionary==1', { | |
585 | 'defines': ['MOZC_USE_SEPARATE_DICTIONARY'], | |
578 | ['use_separate_dataset==1', { | |
579 | 'defines': ['MOZC_USE_SEPARATE_DATASET'], | |
586 | 580 | }], |
587 | 581 | ['use_packed_dictionary==1', { |
588 | 582 | 'defines': ['MOZC_USE_PACKED_DICTIONARY'], |