Codebase list mozc / 30c5d0d
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
13 changed file(s) with 141 addition(s) and 270 deletion(s). Raw diff Collapse all Expand all
205205 'target_name': 'assets',
206206 'type': 'none',
207207 'dependencies': [
208 'assets_connection_data',
209208 'assets_credits',
210 'assets_dictionary',
209 'assets_mozc_dataset',
211210 'assets_touch_stat_data',
212211 ]
213212 },
223222 }],
224223 },
225224 {
226 'target_name': 'assets_connection_data',
225 'target_name': 'assets_mozc_dataset',
227226 'type': 'none',
228227 'conditions': [
229 ['use_separate_connection_data==1',
228 ['use_separate_dataset==1',
230229 {
231230 'actions': [
232231 {
233 'action_name': 'assets_copy_connection_data',
232 'action_name': 'assets_copy_dataset',
234233 'inputs': [
235 '<(connection_data)',
234 '<(mozc_dataset)',
236235 ],
237236 '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',
265238 ],
266239 'action': [
267240 # Note that multiple output files cannot be handled
646619 'action': [
647620 'python', 'run_android_test.py',
648621 '--android_home=<(android_home)',
649 '--mozc_connection_data_file=<(connection_data)',
650622 '--mozc_connection_text_data_file=<(connection_text_data)',
651623 '--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)',
654626 '--mozc_test_connection_text_data_file=<(test_connection_text_data)',
655627 '--native_abi=<(abi)',
656628 '--output_report_dir=<(test_report_dir)',
5151 '<(android_home)/extras/android/support/v13/android-support-v13.jar',
5252 ],
5353 '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',
5555 'test_connection_text_data': '<(shared_intermediate_mozc_dir)/data_manager/testing/connection_single_column.txt',
5656 # e.g. xxxx/out_android/gtest_report
5757 'test_report_dir': '<(SHARED_INTERMEDIATE_DIR)/../../gtest_report',
7474 # and Fedora (jsr-305.jar).
7575 # TODO(yukawa): We should not rely on "find" command here.
7676 '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',
7978 'connection_text_data': '<(shared_intermediate_mozc_dir)/data_manager/oss/connection_single_column.txt',
8079 'native_test_small_targets': [
8180 'oss_data_manager_test',
5454 namespace mozc {
5555 namespace jni {
5656 namespace {
57 jobject g_connection_data_buffer;
58 jobject g_dictionary_buffer;
57 jobject g_mozc_data_buffer;
5958
6059 // Returns a job setting for usage stats job.
6160 const Scheduler::JobSetting GetJobSetting() {
9190 DISALLOW_COPY_AND_ASSIGN(SessionHandlerSingletonAdapter);
9291 };
9392
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) {
9995 // First of all, set the user profile directory.
10096 SystemUtil::SetUserProfileDirectory(user_profile_directory);
10197
102 // Initialize Java native callback proxy.
98 // Initializes Java native callback proxy.
10399 JavaHttpClientProxy::SetJavaVM(vm);
104100
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);
109103
110104 mozc::Singleton<SessionHandlerSingletonAdapter>::get()->getHandler()
111105 ->AddObserver(Singleton<session::SessionUsageObserver>::get());
112106
113 // Start usage stats timer.
107 // Starts usage stats timer.
114108 mozc::Scheduler::AddJob(GetJobSetting());
115109 }
116110
142136 void JNICALL onPostLoad(JNIEnv *env,
143137 jclass clazz,
144138 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);
150142
151143 const char *utf8_user_profile_directory_path =
152144 env->GetStringUTFChars(user_profile_directory_path, nullptr);
154146 JavaVM *vm = NULL;
155147 env->GetJavaVM(&vm);
156148
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));
163152 env->ReleaseStringUTFChars(user_profile_directory_path,
164153 utf8_user_profile_directory_path);
165154 }
197186 "([B)[B",
198187 reinterpret_cast<void*>(&mozc::jni::evalCommand)},
199188 {"onPostLoad",
200 "(Ljava/lang/String;Ljava/nio/Buffer;Ljava/nio/Buffer;)V",
189 "(Ljava/lang/String;Ljava/nio/Buffer;)V",
201190 reinterpret_cast<void*>(&mozc::jni::onPostLoad)},
202191 {"getVersion",
203192 "()Ljava/lang/String;",
225214 // Delete global references.
226215 JNIEnv *env = mozc::AndroidUtil::GetEnv(vm);
227216 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);
230218 }
231219 }
232220 } // extern "C"
103103 help='[NATIVE] Limits testcases to run.')
104104 parser.add_option('--native_abi', dest='abi', default='armeabi',
105105 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.')
112109 parser.add_option('--mozc_connection_text_data_file',
113110 dest='mozc_connection_text_data_file', default=None,
114111 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.')
118115 parser.add_option('--mozc_test_connection_text_data_file',
119116 dest='mozc_test_connection_text_data_file', default=None,
120117 help='[NATIVE] Path to connection_single_column.txt file.')
276273 self._RunCommand('rm', remote_report_path)
277274
278275 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,
281278 mozc_data_dir):
282279 """Set up the android to run tests."""
283280 self.WaitForMount()
291288 # data is set at jni loading time, but it is necessary to somehow
292289 # set the data in native tests. So, copy the dictionary data to the
293290 # emulator.
294 self.CopyFile(host_path=dictionary_data,
291 self.CopyFile(host_path=mozc_dataset,
295292 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'),
301294 operation='push')
302295 self.CopyFile(host_path=connection_text_data,
303296 remote_path=os.path.join(remote_dir,
304297 'data_manager', 'android',
305298 'connection_single_column.txt'),
306299 operation='push')
307 self.CopyFile(host_path=test_connection_data,
300 self.CopyFile(host_path=test_dataset,
308301 remote_path=os.path.join(remote_dir,
309302 'data_manager', 'testing',
310 'connection_data.data'),
303 'mock_mozc.data'),
311304 operation='push')
312305 self.CopyFile(host_path=test_connection_text_data,
313306 remote_path=os.path.join(remote_dir,
338331 error_messages = []
339332 self.SetUpTest(options.remote_device, options.remote_mount_point,
340333 options.remote_dir,
341 options.mozc_dictionary_data_file,
342 options.mozc_connection_data_file,
334 options.mozc_dataset_file,
343335 options.mozc_connection_text_data_file,
344 options.mozc_test_connection_data_file,
336 options.mozc_test_dataset_file,
345337 options.mozc_test_connection_text_data_file,
346338 options.mozc_data_dir)
347339 if options.testcase:
5555 // The file name of the system dictionary and connection data file in the apk.
5656 // This is determined in build.xml.
5757 // ".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";
6059
6160 @Override
6261 public void initialize(Context context) {
7675 }
7776 }
7877
79 // Get buffers for the dictionary from the raw .apk file.
78 // Get a buffer for the dictionary from the raw .apk file.
8079 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);
8582
8683 // Get Java package's version name, to check the version consistency with libmozc.so
8784 // Note that obtained version name is suffixed by android architecture (e.g., -arm).
9390 }
9491
9592 // Load the shared object.
96 MozcJNI.load(userProfileDirectory.getAbsolutePath(),
97 dictionaryBuffer, connectionDataBuffer, matcher.group(1));
93 MozcJNI.load(userProfileDirectory.getAbsolutePath(), dataSetBuffer, matcher.group(1));
9894 } catch (IOException e) {
9995 MozcLog.e("Failed to load system dictionary.", e);
10096 throw new RuntimeException(e);
4646 /**
4747 * Loads and initializes the JNI library.
4848 *
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.)
5150 * @param expectedVersion expected version name of .so
5251 */
5352 static void load(
54 String userProfileDirectoryPath, Buffer dictionaryBuffer, Buffer connectionDataBuffer,
55 String expectedVersion) {
53 String userProfileDirectoryPath, Buffer mozcDataBuffer, String expectedVersion) {
5654 Preconditions.checkNotNull(userProfileDirectoryPath);
57 Preconditions.checkNotNull(dictionaryBuffer);
58 Preconditions.checkNotNull(connectionDataBuffer);
55 Preconditions.checkNotNull(mozcDataBuffer);
5956 Preconditions.checkNotNull(expectedVersion);
6057
6158 if (isLoaded) {
8077 message.append(" Server:").append(nativeVersion);
8178 throw new UnsatisfiedLinkError(message.toString());
8279 }
83 onPostLoad(userProfileDirectoryPath, dictionaryBuffer, connectionDataBuffer);
80 onPostLoad(userProfileDirectoryPath, mozcDataBuffer);
8481 isLoaded = true;
8582 MozcLog.d("end MozcJNI#load " + System.nanoTime());
8683 }
103100 * of dictionary data from Java as only Java knows where the data is in our context.
104101 */
105102 private static synchronized native void onPostLoad(
106 String userProfileDirectoryPath, Buffer dictionaryData, Buffer connectionData);
103 String userProfileDirectoryPath, Buffer mozcDataBuffer);
107104
108105 /**
109106 * @return Version string of shared object
811811 # Dictionary configuration
812812 if target_platform == 'Android':
813813 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'])
817815 gyp_options.extend(['-D', 'use_1byte_cost_for_connection_data=1'])
818816 gyp_options.extend(['-D', 'use_packed_dictionary=0'])
819817 elif target_platform == 'NaCl':
820818 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'])
824820 gyp_options.extend(['-D', 'use_1byte_cost_for_connection_data=0'])
825821 gyp_options.extend(['-D', 'use_packed_dictionary=1'])
826822 else:
827823 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'])
831825 gyp_options.extend(['-D', 'use_1byte_cost_for_connection_data=0'])
832826 gyp_options.extend(['-D', 'use_packed_dictionary=0'])
833827
192192 'type': 'none',
193193 'toolsets': ['host'],
194194 'conditions': [
195 ['use_separate_dictionary==1',{
195 ['use_separate_dataset==1',{
196196 'dependencies': [
197197 'gen_separate_dictionary_data_for_<(dataset_tag)#host',
198198 ],
210210 'type': 'none',
211211 'toolsets': ['host'],
212212 'conditions': [
213 ['use_separate_connection_data==1',{
213 ['use_separate_dataset==1',{
214214 'dependencies': [
215215 'gen_separate_connection_data_for_<(dataset_tag)#host',
216216 ],
2828
2929 #include "data_manager/oss/oss_data_manager.h"
3030
31 #include "base/embedded_file.h"
3132 #include "base/logging.h"
3233 #include "base/port.h"
3334 #include "converter/boundary_struct.h"
4344
4445 namespace mozc {
4546 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
4865 // kLidGroup[] is defined in the following automatically generated header file.
4966 #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;
5189
5290 const uint8 *OssDataManager::GetPosGroupData() const {
5391 DCHECK(kLidGroup != NULL);
5492 return kLidGroup;
5593 }
5694
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 }
80100
81101 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 }
105104
106105 void OssDataManager::GetSystemDictionaryData(
107106 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 }
120109
121110 namespace {
122111 // Automatically generated headers containing data set for segmenter.
161150 *size = arraysize(kReadingCorrections);
162151 }
163152
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
194153 void OssDataManager::GetCollocationData(const char **array,
195154 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);
203156 }
204157
205158 void OssDataManager::GetCollocationSuppressionData(const char **array,
206159 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 }
215162
216163 void OssDataManager::GetSuggestionFilterData(const char **data,
217164 size_t *size) const {
218 *data = kSuggestionFilterData_data;
219 *size = kSuggestionFilterData_size;
165 manager_.GetSuggestionFilterData(data, size);
220166 }
221167
222168 namespace {
5353 '<(platform_data_dir)/reading_correction.tsv',
5454 ],
5555 '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",
5858 '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',
6161 },
6262 # This 'includes' defines the following targets:
6363 # - oss_data_manager (type: static_library)
3030 #define MOZC_DATA_MANAGER_OSS_OSS_DATA_MANAGER_H_
3131
3232 #include "base/port.h"
33 #include "data_manager/data_manager.h"
3334 #include "data_manager/oss/oss_user_pos_manager.h"
3435
3536 namespace mozc {
3738
3839 class OssDataManager : public OssUserPosManager {
3940 public:
40 OssDataManager() {}
41 virtual ~OssDataManager() {}
41 OssDataManager();
42 ~OssDataManager() override;
4243
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);
5245
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;
7163 #ifndef NO_USAGE_REWRITER
72 virtual void GetUsageRewriterData(
64 void GetUsageRewriterData(
7365 const ConjugationSuffix **base_conjugation_suffix,
7466 const ConjugationSuffix **conjugation_suffix_data,
7567 const int **conjugation_suffix_data_index,
76 const UsageDictItem **usage_data_value) const;
68 const UsageDictItem **usage_data_value) const override;
7769 #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;
8072
8173 private:
74 DataManager manager_;
8275 DISALLOW_COPY_AND_ASSIGN(OssDataManager);
8376 };
8477
575575 '<@(linux_ldflags)',
576576 ],
577577 }],
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'],
586580 }],
587581 ['use_packed_dictionary==1', {
588582 'defines': ['MOZC_USE_PACKED_DICTIONARY'],
00 MAJOR=2
11 MINOR=17
2 BUILD=2456
2 BUILD=2457
33 REVISION=102
44 # NACL_DICTIONARY_VERSION is the target version of the system dictionary to be
55 # downloaded by NaCl Mozc.