tag_array = bundle_get_str_array(msg, "return_tag", &len_tag_array);
token_array = bundle_get_str_array(msg, "return_token", &len_token_array);
- for (int i=0; i < len_tag_array; i++) {
- pos_tag_pair = (pos_tag_s* )calloc(1, sizeof(pos_tag_s));
- if (pos_tag_pair) {
- pos_tag_pair->token = token_array[i];
- pos_tag_pair->tag = tag_array[i];
- }
+ if (tag_array && token_array) {
+ for (int i=0; i < len_tag_array; i++) {
+ pos_tag_pair = (pos_tag_s* )calloc(1, sizeof(pos_tag_s));
+ if (pos_tag_pair) {
+ pos_tag_pair->token = token_array[i];
+ pos_tag_pair->tag = tag_array[i];
+ }
- LOGD("tag: %s, token : %s", tag_array[i], token_array[i]);
+ LOGD("tag: %s, token : %s", tag_array[i], token_array[i]);
- glist = g_list_append(glist, pos_tag_pair);
+ glist = g_list_append(glist, pos_tag_pair);
+ }
}
pos_tag_result_h = glist;
word_array = bundle_get_str_array(msg, "return_token", &len_word_array);
- for (int i=0; i < len_word_array; i++) {
- LOGD("word : %s", word_array[i]);
- glist = g_list_append(glist, (void *)word_array[i]);
+ if (word_array) {
+ for (int i=0; i < len_word_array; i++) {
+ LOGD("word : %s", word_array[i]);
+ glist = g_list_append(glist, (void *)word_array[i]);
+ }
}
word_tokenize_result_h = glist;
if (nh->word_tokenize_result_cb)
nh->word_tokenize_result_cb((unsigned int)atoi(request_id), word_tokenize_result_h, nh->word_tokenize_result_data);
+
+ if (g_list_length(glist) > 0) {
+ g_list_free(glist);
+ glist = NULL;
+ }
}
static void process_language_detect_result(nlp_h nh, bundle *msg)
bundle_get_str(msg, "request_id", &request_id);
LOGD("id : %s", request_id);
- const char **word_array = NULL;
- int len_word_array = 0;
- //GList *glist = NULL;
- //nlp_word_tokenize_result_h word_tokenize_result_h = NULL;
-
- word_array = bundle_get_str_array(msg, "return_token", &len_word_array);
+ const char **language_array = NULL;
+ int len_language_array = 0;
+ const char *detect_language = NULL;
+ language_array = bundle_get_str_array(msg, "return_token", &len_language_array);
+ if (language_array) {
+ for (int i=0; i < len_language_array; i++) {
+ LOGD("language : %s", language_array[i]);
+ }
- for (int i=0; i < len_word_array; i++) {
- LOGD("language : %s", word_array[i]);
- //glist = g_list_append(glist, (void *)word_array[i]);
+ detect_language = language_array[0];
}
- //word_tokenize_result_h = glist;
-
if (nh->language_detect_result_cb)
- nh->language_detect_result_cb((unsigned int)atoi(request_id), word_array[0], nh->language_detect_result_data);
+ nh->language_detect_result_cb((unsigned int)atoi(request_id), detect_language, nh->language_detect_result_data);
}
//LCOV_EXCL_START
/* next item */
iter = g_list_next(iter);
}
-
- g_list_free(glist);
- glist = NULL;
}
return NLP_ERROR_NONE;
}
-EXPORT_API int nlp_request_language_detect(nlp_h nh, const char *str, unsigned int *request_id)
+ EXPORT_API int nlp_request_language_detect(nlp_h nh, const char *str, unsigned int *request_id)
{
return send_request(nh, "langdetect", str, request_id);
}