Пример #1
0
static PyObject* get_words(Scws* self, PyObject* args){
    char *text;
    char *attr = NULL;
    if(!PyArg_ParseTuple(args, "s|s", &text, &attr)){
        return NULL;
    }
    scws_send_text(self->scws, text, strlen(text));
    scws_top_t res, cur;
    if(attr){
        cur = res = scws_get_words(self->scws, attr);
    }
    else{
        cur = res = scws_get_words(self->scws, NULL);
    }
    PyObject* result = PyList_New(0);
    while (cur != NULL){
        PyObject* aword = PyList_New(4);
        PyObject* word = PyString_FromString(cur->word);
        PyObject* word_attr = PyString_FromString(cur->attr);
        PyObject* weight = PyFloat_FromDouble(cur->weight);
        PyObject* times = PyInt_FromLong(cur->times);
        PyList_SetItem(aword, 0, word);
        PyList_SetItem(aword, 1, times);
        PyList_SetItem(aword, 2, weight);
        PyList_SetItem(aword, 3, word_attr);
        PyList_Append(result, aword);
        Py_DECREF(aword);
        cur = cur->next;
    }
    scws_free_tops(res);
    return result;
}
Пример #2
0
map<string,int> Getfeature::feature_get(string&text){
     map<string,int> features;     
     string fe;
     scws_top_t cur;
     scws_send_text(Getfeature::s,text.c_str(),text.length());
     ///按照词性获得结果
     cur=scws_get_words(Getfeature::s,const_cast<char*>((*(env->conf))["policy"]["fe_policy"].c_str()));
     if(cur!=0){
	  while(cur!=0){
	       fe=cur->word;
	       if(fe.length()>=2*3)
		    features.insert(pair<string,int> (fe,cur->times));
	       cur=cur->next;
	  }
	   scws_free_tops(cur);
     }
     return features;
}