/*------------------------------------------------------------------------- * * LemClientC.cpp * * * Лемматизатор. * * *------------------------------------------------------------------------- */ // Local Includes #include "LemClient.hpp" #include "LemClientC.h" // C Includes #include // // Лемматизатор // struct LemmWrapper { int lang; lem::Lemmatizer * lemmatizer; }; // // Инициализация лемматизатора // void * LemmatizerInit(int iLang) { LemmWrapper * pLemmWrapper = NULL; try { pLemmWrapper = new LemmWrapper; pLemmWrapper -> lang = iLang; pLemmWrapper -> lemmatizer = NULL; } catch(...) { if (pLemmWrapper != NULL) { delete pLemmWrapper; pLemmWrapper = NULL; } } return pLemmWrapper; } // // Загрузка словарей // int LemmatizerLoadDict(void * vLemmWrapper) { using lem::Lemmatizer; LemmWrapper * pLemmWrapper = static_cast (vLemmWrapper); try { pLemmWrapper -> lemmatizer = new Lemmatizer("", pLemmWrapper -> lang); return 1; } catch(...) { if (pLemmWrapper -> lemmatizer != NULL) { delete pLemmWrapper -> lemmatizer; } } return -1; } // // Список первых форм // char ** LemmatizerFirstForm(void * vLemmWrapper, char * szRequest) { using std::vector; using lem::LemmResult; LemmWrapper * pLemmWrapper = static_cast (vLemmWrapper); if (pLemmWrapper == NULL || pLemmWrapper -> lemmatizer == NULL) { return NULL; } try { vector vResult = pLemmWrapper -> lemmatizer -> Lemmatize(szRequest); char ** sFirstForms = (char **)malloc(vResult.size() + 1); size_t iI = 0; vector::const_iterator itvResult = vResult.begin(); while (itvResult != vResult.end()) { sFirstForms[iI] = strdup(itvResult -> first_form.c_str()); itvResult++; iI++; } sFirstForms[iI] = NULL; return sFirstForms; } catch(...) { ;; } return NULL; } // // Завершение лемматизатора // void LemmatizerDestroy(void * vLemmWrapper) { LemmWrapper * pLemmWrapper = static_cast (vLemmWrapper); if (pLemmWrapper == NULL) { return; } try { if (pLemmWrapper -> lemmatizer != NULL) { delete pLemmWrapper -> lemmatizer; } delete pLemmWrapper; } catch(...) { ;; } } // End.