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);
{
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);
{
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);
{
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");
{
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");
{
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: ");
}
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)
{
}
}
-int nltk_getSizeFromTuple(PyObject* tuple)
+int nltk_get_size_from_tuple(PyObject* tuple)
{
if PyTuple_Check(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)
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)
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
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
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;