void Scws::GetResult(string content ,vector<SCWSRESULT> &v) { scws_res_t res, cur; scws_send_text(s,content.c_str() ,content.length()); while (res = cur = scws_get_result(s)) { while (cur != NULL) { //add the result into the vector SCWSRESULT result; result.word = string(content,cur->off ,cur->len); result.weight = (int)cur->idf; v.push(result); //offset the cur cur = cur->next; } scws_free_result(res); } scws_free(s); }
/* * Module unload callback */ void _PG_fini(void) { if (zhprs_scws) scws_free(zhprs_scws); zhprs_scws = NULL; }
/* * Module unload callback */ void _PG_fini(void) { if (pgscws_scws) scws_free(pgscws_scws); pgscws_scws = NULL; }
Datum zhprs_end(PG_FUNCTION_ARGS) { ParserState *pst = (ParserState *) PG_GETARG_POINTER(0); if (pst->scws) scws_free(pst->scws); pfree(pst); PG_RETURN_VOID(); }
static ZEND_RSRC_DTOR_FUNC(php_scws_dtor) { if (rsrc->ptr) { struct php_scws *ps = (struct php_scws *) rsrc->ptr; scws_free(ps->s); DELREF_SCWS(ps->zt); efree(ps); rsrc->ptr = NULL; } }
static ZEND_RSRC_DTOR_FUNC(php_scws_dtor) { #if PHP_MAJOR_VERSION == 7 #define rsrc res #endif if (rsrc->ptr) { struct php_scws *ps = (struct php_scws *) rsrc->ptr; scws_free(ps->s); #if PHP_MAJOR_VERSION < 7 DELREF_SCWS(ps->zt); #endif efree(ps); rsrc->ptr = NULL; } #if PHP_MAJOR_VERSION == 7 #undef rsrc #endif }
void scws_send_text_AS3() { char *text = NULL; AS3_MallocString(text, inputString); scws_send_text(s, text, strlen(text)); AS3_DeclareVar(myString, String); //char *result; //result[0] = '\0'; // ensures the memory is an empty string char result[5000]={"0"}; char temp[1000]={'\0'}; printf("%s",result); while (res = cur = scws_get_result(s)) { while (cur != NULL) { printf("WORD: %.*s/%s (IDF = %4.2f)\n", cur->len, text+cur->off, cur->attr, cur->idf); //if((result = malloc(strlen(result)+ cur->len +1)) != NULL){ //if((result = (char*) realloc(strlen(result)+ (cur->len) +1)) != NULL) strncpy(temp, text+cur->off, cur->len); temp[(cur->len)+1]='\0'; strcat(result, temp); strcat(result, ' '); strcat(result, '\0'); //strncpy(new_str,str2); //} else { //printf("malloc failed!\n"); // exit? //} cur = cur->next; } scws_free_result(res); } strcat(result, '\0'); printf("%s",result); AS3_CopyCStringToVar(myString, result, strlen(result)); scws_free(s); //scws_free(result); AS3_Trace(myString); AS3_Return("212"); }
void updateUniverse() { char *text = "Hello, 我名字叫李那曲是一个中国人, 我有时买Q币来玩, 我还听说过C#语言"; if (!(s = scws_new())) { printf("ERROR: cann't init the scws!\n"); //exit(-1); } scws_set_charset(s, "utf8"); scws_set_dict(s, "dict.utf8.xdb", SCWS_XDICT_XDB); scws_set_rule(s, "rules.utf8.ini"); scws_send_text(s, text, strlen(text)); while (res = cur = scws_get_result(s)) { while (cur != NULL) { printf("WORD: %.*s/%s (IDF = %4.2f)\n", cur->len, text+cur->off, cur->attr, cur->idf); cur = cur->next; } scws_free_result(res); } scws_free(s); }
Getfeature::~Getfeature(){ scws_free(s); }
static void Scws_dealloc(Scws* self){ scws_free(self->scws); self->ob_type->tp_free((PyObject*)self); }
static PyObject * scws_scws_free(PyObject * self,PyObject * args){ scws_free(s); return Py_BuildValue("i", 1); }