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;
PRET_VM(!func, NULL, "Input parameter [func] is NULL!");
return PyObject_CallObject(func, args);
}
-
-// This is an example of an method to get attribute of module.
-char* nltk_get_attribute(int z)
-{
- PyObject *pModule, *pFunc;
- PyObject *pArgs;
- char* ch = (char*) malloc(BUF_LEN_256);
- if (ch != NULL)
- {
- memset(ch, 0, BUF_LEN_256);
- pModule = PyImport_ImportModule("site");
- if (pModule != NULL)
- {
- //create args tuple struct to fill the arg one by one ,here ,only create one param with 1
- pArgs = PyTuple_New(1);
- //set a string for item 0 of tuple
- PyTuple_SetItem(pArgs, 0, PyString_FromString("Hello World"));
- //call word_tokenize func with args
- pFunc = PyObject_GetAttrString(pModule, "USER_SITE");
- if (pFunc != NULL) {
- strncpy(ch, PyString_AsString(pFunc), BUF_LEN_256-1);
- } else {
- strncpy(ch, "attribute get error\n", BUF_LEN_256-1);
- }
- } else {
- strncpy(ch, "nltk module import error\n", BUF_LEN_256-1);
- }
- return ch;
- }
- else
- {
- PERR("malloc failed");
- return NULL;
- }
-}