static gchar* lw_morphologyengine_hunspell_stem (LwMorphologyEngine *engine, const gchar *WORD) { //Sanity checks if (engine == NULL) return NULL; if (engine->hunspell == NULL) return NULL; if (WORD == NULL) return NULL; gchar **suggestions; gint total; gchar *output; gint i; total = Hunspell_stem (engine->hunspell, &suggestions, WORD); output = NULL; if (suggestions != NULL) { for (i = total - 1; i >= 0 && output == NULL; i--) //The results at the end tend to be the most core form { if (g_ascii_strcasecmp (WORD, suggestions[i]) != 0) //Make sure we aren't just getting the lower case form of the word output = g_strdup (suggestions[i]); } Hunspell_free_list (engine->hunspell, &suggestions, total); suggestions = NULL; } return output; }
static PyObject * HunSpell_stem(HunSpell * self, PyObject *args) { char *word, **slist; int i, num_slist; PyObject *slist_list; if (!PyArg_ParseTuple(args, "s", &word)) return NULL; slist_list = PyList_New(0); num_slist = Hunspell_stem(self->handle, &slist, word); for (i = 0; i < num_slist; i++) { PyList_Append(slist_list, Py_BuildValue("s", slist[i])); } Hunspell_free_list(self->handle, &slist, num_slist); return slist_list; }