update service source code according to CAPI naming rule 76/184276/2
authorzhangzg <zg84.zhang@samsung.com>
Tue, 17 Jul 2018 02:10:30 +0000 (10:10 +0800)
committerzhang zhigang <zg84.zhang@samsung.com>
Tue, 17 Jul 2018 06:20:50 +0000 (06:20 +0000)
Change-Id: I0a631651e41b6905285bd9cd1189f035a821b805

service/inc/service.h
service/src/service.c

index a7c672c..f62d0ce 100644 (file)
 // This method is exported from nltk_native_library.so
 void nltk_initialize();
 void nltk_finalize();
-PyObject* nltk_getModule(char* m_name);
-PyObject* nltk_getFunctionHandle(PyObject* m_module , char * f_name);
-PyObject* nltk_makeArgsFromPyObject(PyObject* pyobj);
-PyObject* nltk_makeArgsFromString(char* info);
-PyObject* nltk_callFunctionWithArgs(PyObject* m_func, PyObject* args);
-int nltk_getSizeFromList(PyObject* list);
-int nltk_getSizeFromTuple(PyObject* tuple);
-PyObject* nltk_getElementFromTupleByIndex(PyObject* tuple, int index);
-PyObject* nltk_getElementFromListByIndex(PyObject* list, int index);
-char* nltk_getStringFromElement(PyObject* elm);
-char* nltk_getattrib(int z);
+PyObject* nltk_get_module(char* name);
+PyObject* nltk_get_function_handle(PyObject* module , char * func_name);
+PyObject* nltk_make_args_from_pyobject(PyObject* pyobj);
+PyObject* nltk_make_args_from_string(char* info);
+PyObject* nltk_call_function_with_args(PyObject* func, PyObject* args);
+int nltk_get_size_from_list(PyObject* list);
+int nltk_get_size_from_tuple(PyObject* tuple);
+PyObject* nltk_get_element_from_tuple_by_index(PyObject* tuple, int index);
+PyObject* nltk_get_element_from_list_by_index(PyObject* list, int index);
+char* nltk_get_string_from_element(PyObject* elm);
+char* nltk_get_attribute(int z);
 PyObject* globe_nltk;
 PyObject* globe_lemm;
 PyObject* globe_lang;
index db88ec3..b325d26 100644 (file)
@@ -45,14 +45,14 @@ message_port_cb(int local_port_id, const char *remote_app_id, const char *remote
     switch (i) {
     case 1:
     {
-        args = nltk_makeArgsFromString(info);
-        lists = nltk_callFunctionWithArgs(nltk_getFunctionHandle(globe_nltk,"word_tokenize"), args);
-        len = nltk_getSizeFromList(lists);
+        args = nltk_make_args_from_string(info);
+        lists = nltk_call_function_with_args(nltk_get_function_handle(globe_nltk,"word_tokenize"), args);
+        len = nltk_get_size_from_list(lists);
         char *s_token[128] = {NULL,};
         for(int i = 0 ;i < len ;i++)
         {
             s_token[i] = (char*)malloc(128*sizeof(char));
-            strcpy(s_token[i]  ,nltk_getStringFromElement(nltk_getElementFromListByIndex(lists, i)));
+            strcpy(s_token[i]  ,nltk_get_string_from_element(nltk_get_element_from_list_by_index(lists, i)));
         }
         bundle_add_str(reply, "command", "word_tokenize");
         bundle_add_str_array(reply, "return", s_token, len);
@@ -63,19 +63,19 @@ message_port_cb(int local_port_id, const char *remote_app_id, const char *remote
     {
         char *s_tag[128] = {NULL,};
         char *s_token[128] = {NULL,};
-        args = nltk_makeArgsFromString(info);
-        lists = nltk_callFunctionWithArgs(nltk_getFunctionHandle(globe_nltk,"word_tokenize"), args);
-        postag_module = nltk_getFunctionHandle(globe_nltk,"pos_tag");
-        args = nltk_makeArgsFromPyObject(lists);
-        postag_result = nltk_callFunctionWithArgs(postag_module, args);
-        len = nltk_getSizeFromList(postag_result);
+        args = nltk_make_args_from_string(info);
+        lists = nltk_call_function_with_args(nltk_get_function_handle(globe_nltk,"word_tokenize"), args);
+        postag_module = nltk_get_function_handle(globe_nltk,"pos_tag");
+        args = nltk_make_args_from_pyobject(lists);
+        postag_result = nltk_call_function_with_args(postag_module, args);
+        len = nltk_get_size_from_list(postag_result);
         for(int i = 0 ;i < len ;i++)
         {
             s_token[i] = (char*)malloc(128*sizeof(char));
             s_tag[i] = (char*)malloc(128*sizeof(char));
-            pos_elm_tuple = nltk_getElementFromListByIndex(postag_result, i);
-            strcpy(s_tag[i] , nltk_getStringFromElement(nltk_getElementFromTupleByIndex(pos_elm_tuple, 0)));
-            strcpy(s_token[i] , nltk_getStringFromElement(nltk_getElementFromTupleByIndex(pos_elm_tuple, 1)));
+            pos_elm_tuple = nltk_get_element_from_list_by_index(postag_result, i);
+            strcpy(s_tag[i] , nltk_get_string_from_element(nltk_get_element_from_tuple_by_index(pos_elm_tuple, 0)));
+            strcpy(s_token[i] , nltk_get_string_from_element(nltk_get_element_from_tuple_by_index(pos_elm_tuple, 1)));
         }
         bundle_add_str(reply, "command", "pos_tag");
         bundle_add_str_array(reply, "return_tag", s_tag, len);
@@ -87,24 +87,24 @@ message_port_cb(int local_port_id, const char *remote_app_id, const char *remote
     {
         char *s_tag[128] = {NULL,};
         char *s_token[128] = {NULL,};
-        args = nltk_makeArgsFromString(info);
-        lists = nltk_callFunctionWithArgs(nltk_getFunctionHandle(globe_nltk,"word_tokenize"), args);
-        postag_module = nltk_getFunctionHandle(globe_nltk,"pos_tag");
-        args = nltk_makeArgsFromPyObject(lists);
-        postag_result = nltk_callFunctionWithArgs(postag_module, args);
-        args = nltk_makeArgsFromPyObject(postag_result);
-        ne_module = nltk_getFunctionHandle(globe_nltk,"ne_chunk");
-        ne_result = nltk_callFunctionWithArgs(ne_module, args);
-        lv_module = nltk_getFunctionHandle(ne_result, "leaves");
-        lv_result = nltk_callFunctionWithArgs(lv_module, NULL);
-        len = nltk_getSizeFromList(lv_result);
+        args = nltk_make_args_from_string(info);
+        lists = nltk_call_function_with_args(nltk_get_function_handle(globe_nltk,"word_tokenize"), args);
+        postag_module = nltk_get_function_handle(globe_nltk,"pos_tag");
+        args = nltk_make_args_from_pyobject(lists);
+        postag_result = nltk_call_function_with_args(postag_module, args);
+        args = nltk_make_args_from_pyobject(postag_result);
+        ne_module = nltk_get_function_handle(globe_nltk,"ne_chunk");
+        ne_result = nltk_call_function_with_args(ne_module, args);
+        lv_module = nltk_get_function_handle(ne_result, "leaves");
+        lv_result = nltk_call_function_with_args(lv_module, NULL);
+        len = nltk_get_size_from_list(lv_result);
         for(int i = 0 ;i < len ;i++)
         {
             s_token[i] = (char*)malloc(128*sizeof(char));
             s_tag[i] = (char*)malloc(128*sizeof(char));
-            pos_elm_tuple = nltk_getElementFromListByIndex(lv_result, i);
-            strcpy(s_tag[i] , nltk_getStringFromElement(nltk_getElementFromTupleByIndex(pos_elm_tuple, 0)));
-            strcpy(s_token[i] , nltk_getStringFromElement(nltk_getElementFromTupleByIndex(pos_elm_tuple, 1)));
+            pos_elm_tuple = nltk_get_element_from_list_by_index(lv_result, i);
+            strcpy(s_tag[i] , nltk_get_string_from_element(nltk_get_element_from_tuple_by_index(pos_elm_tuple, 0)));
+            strcpy(s_token[i] , nltk_get_string_from_element(nltk_get_element_from_tuple_by_index(pos_elm_tuple, 1)));
         }
         bundle_add_str(reply, "command", "ne_chunk");
         bundle_add_str_array(reply, "return_tag", s_tag, len);
@@ -116,12 +116,12 @@ message_port_cb(int local_port_id, const char *remote_app_id, const char *remote
     {
         char  *buf[1] = {NULL,};
         buf[0] = (char*)malloc(128*sizeof(char));
-        args = nltk_makeArgsFromString(info);
-        lm_module = nltk_getFunctionHandle(globe_lemm,"WordNetLemmatizer");
-        lm_object = nltk_callFunctionWithArgs(lm_module, NULL);
-        lm_module = nltk_getFunctionHandle(lm_object, "lemmatize");
-        lm_result = nltk_callFunctionWithArgs(lm_module, args);
-        strcpy(buf[0] , nltk_getStringFromElement(lm_result));
+        args = nltk_make_args_from_string(info);
+        lm_module = nltk_get_function_handle(globe_lemm,"WordNetLemmatizer");
+        lm_object = nltk_call_function_with_args(lm_module, NULL);
+        lm_module = nltk_get_function_handle(lm_object, "lemmatize");
+        lm_result = nltk_call_function_with_args(lm_module, args);
+        strcpy(buf[0] , nltk_get_string_from_element(lm_result));
         bundle_add_str(reply, "command", "lemmatize");
         bundle_add_str_array(reply, "return_token", buf, 1);
         dlog_print(DLOG_INFO, LOG_TAG, "lemmatize process done");
@@ -131,10 +131,10 @@ message_port_cb(int local_port_id, const char *remote_app_id, const char *remote
     {
         char  *buf[1] = {NULL,};
         buf[0] = (char*)malloc(128*sizeof(char));
-        args = nltk_makeArgsFromString(info);
-        ld_module = nltk_getFunctionHandle(globe_lang,"detect");
-        ld_result = nltk_callFunctionWithArgs(ld_module, args);
-        strcpy(buf[0] , nltk_getStringFromElement(ld_result));
+        args = nltk_make_args_from_string(info);
+        ld_module = nltk_get_function_handle(globe_lang,"detect");
+        ld_result = nltk_call_function_with_args(ld_module, args);
+        strcpy(buf[0] , nltk_get_string_from_element(ld_result));
         bundle_add_str(reply, "command", "langdetect");
         bundle_add_str_array(reply, "return_token", buf, 1);
         dlog_print(DLOG_INFO, LOG_TAG, "langdetect process done");
@@ -167,11 +167,11 @@ bool service_app_create(void *data)
     {
         dlog_print(DLOG_INFO, LOG_TAG, "NLTK ####Port register success: %d", port_id);
         nltk_initialize();
-        globe_nltk = nltk_getModule("nltk");
+        globe_nltk = nltk_get_module("nltk");
         dlog_print(DLOG_INFO, LOG_TAG, "nltk library loaded success: ");
-        globe_lemm = nltk_getModule("nltk.stem");
+        globe_lemm = nltk_get_module("nltk.stem");
         dlog_print(DLOG_INFO, LOG_TAG, "nltk stem library loaded success: ");
-        globe_lang = nltk_getModule("langdetect");
+        globe_lang = nltk_get_module("langdetect");
         dlog_print(DLOG_INFO, LOG_TAG, "langdetect library loaded success: ");
     }
 
@@ -243,12 +243,12 @@ void nltk_finalize()
     Py_Finalize();
 }
 
-PyObject* nltk_getModule(char* m_name)
+PyObject* nltk_get_module(char* name)
 {
-    return PyImport_ImportModuleNoBlock(m_name);
+    return PyImport_ImportModuleNoBlock(name);
 }
 
-int nltk_getSizeFromList(PyObject* list)
+int nltk_get_size_from_list(PyObject* list)
 {
     if PyList_Check(list)
     {
@@ -260,7 +260,7 @@ int nltk_getSizeFromList(PyObject* list)
     }
 }
 
-int nltk_getSizeFromTuple(PyObject* tuple)
+int nltk_get_size_from_tuple(PyObject* tuple)
 {
     if PyTuple_Check(tuple)
     {
@@ -272,7 +272,7 @@ int nltk_getSizeFromTuple(PyObject* tuple)
     }
 }
 
-PyObject* nltk_getElementFromListByIndex(PyObject* list, int index)
+PyObject* nltk_get_element_from_list_by_index(PyObject* list, int index)
 {
     PyObject* element;
     if PyList_Check(list)
@@ -299,7 +299,7 @@ char* nltk_getStringFromListElement(PyObject* elm)
     return PyString_AsString(elm);
 }
 
-PyObject* nltk_getElementFromTupleByIndex(PyObject* tuple, int index)
+PyObject* nltk_get_element_from_tuple_by_index(PyObject* tuple, int index)
 {
     PyObject* element;
     if PyTuple_Check(tuple)
@@ -321,19 +321,19 @@ PyObject* nltk_getElementFromTupleByIndex(PyObject* tuple, int index)
     return element;
 }
 
-char* nltk_getStringFromElement(PyObject* elm)
+char* nltk_get_string_from_element(PyObject* elm)
 {
     char* ch = (char*) malloc(255);
     strcpy(ch, PyString_AsString(elm));
     return ch;
 }
 
-PyObject* nltk_getFunctionHandle(PyObject* m_module, char * f_name)
+PyObject* nltk_get_function_handle(PyObject* module, char * func_name)
 {
-    return PyObject_GetAttrString(m_module, f_name);
+    return PyObject_GetAttrString(module, func_name);
 }
 
-PyObject* nltk_makeArgsFromString(char* info)
+PyObject* nltk_make_args_from_string(char* info)
 {
     PyObject *pArgs;
     //create args tuple struct to fill the arg one by one  ,here , only create one string with 1
@@ -342,7 +342,7 @@ PyObject* nltk_makeArgsFromString(char* info)
     return pArgs;
 }
 
-PyObject* nltk_makeArgsFromPyObject(PyObject* pyobj)
+PyObject* nltk_make_args_from_pyobject(PyObject* pyobj)
 {
     PyObject *pArgs;
     //create args tuple struct to fill the arg one by one  ,here ,only create one python object with 1
@@ -352,13 +352,13 @@ PyObject* nltk_makeArgsFromPyObject(PyObject* pyobj)
     return pArgs;
 }
 
-PyObject* nltk_callFunctionWithArgs(PyObject* m_func, PyObject* args)
+PyObject* nltk_call_function_with_args(PyObject* func, PyObject* args)
 {
-    return PyObject_CallObject(m_func, args);
+    return PyObject_CallObject(func, args);
 }
 
 // This is an example of an method to get attribute of module.
-char* nltk_getattrib(int z)
+char* nltk_get_attribute(int z)
 {
     PyObject *pModule, *pFunc;
     PyObject *pArgs;