diff options
author | Kenneth Heafield <github@kheafield.com> | 2014-01-28 21:34:00 +0400 |
---|---|---|
committer | Kenneth Heafield <github@kheafield.com> | 2014-01-28 21:34:00 +0400 |
commit | ffc8e2f7ab839d42bc9e3644f07c98bd65f49ff9 (patch) | |
tree | 5cb5a566dfb8146048edd97a7afc9a0cf603003a /python | |
parent | 1b3f1d5929e229748f6270d1a10fb7c2b9319217 (diff) |
Update python wrapper for change in virtual interface
Diffstat (limited to 'python')
-rw-r--r-- | python/kenlm.cpp | 366 | ||||
-rw-r--r-- | python/kenlm.pxd | 4 | ||||
-rw-r--r-- | python/kenlm.pyx | 8 |
3 files changed, 189 insertions, 189 deletions
diff --git a/python/kenlm.cpp b/python/kenlm.cpp index d401047..c7052fc 100644 --- a/python/kenlm.cpp +++ b/python/kenlm.cpp @@ -1,4 +1,4 @@ -/* Generated by Cython 0.19.1 on Wed Jun 5 13:00:19 2013 */ +/* Generated by Cython 0.19.1 on Tue Jan 28 09:32:20 2014 */ #define PY_SSIZE_T_CLEAN #ifndef CYTHON_USE_PYLONG_INTERNALS @@ -493,23 +493,8 @@ static const char *__pyx_f[] = { }; /*--- Type declarations ---*/ -struct __pyx_obj_5kenlm_LanguageModel; struct __pyx_obj_5kenlm___pyx_scope_struct__full_scores; - -/* "kenlm.pyx":10 - * raise TypeError('Cannot convert %s to string' % type(data)) - * - * cdef class LanguageModel: # <<<<<<<<<<<<<< - * cdef Model* model - * cdef public bytes path - */ -struct __pyx_obj_5kenlm_LanguageModel { - PyObject_HEAD - lm::base::Model *model; - PyObject *path; - const lm::base::Vocabulary *vocab; -}; - +struct __pyx_obj_5kenlm_LanguageModel; /* "kenlm.pyx":44 * return total @@ -532,6 +517,21 @@ struct __pyx_obj_5kenlm___pyx_scope_struct__full_scores { Py_ssize_t __pyx_t_1; }; + +/* "kenlm.pyx":10 + * raise TypeError('Cannot convert %s to string' % type(data)) + * + * cdef class LanguageModel: # <<<<<<<<<<<<<< + * cdef Model* model + * cdef public bytes path + */ +struct __pyx_obj_5kenlm_LanguageModel { + PyObject_HEAD + lm::base::Model *model; + PyObject *path; + const lm::base::Vocabulary *vocab; +}; + #ifndef CYTHON_REFNANNY #define CYTHON_REFNANNY 0 #endif @@ -771,8 +771,8 @@ static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); /*proto*/ /* Module declarations from 'kenlm' */ -static PyTypeObject *__pyx_ptype_5kenlm_LanguageModel = 0; static PyTypeObject *__pyx_ptype_5kenlm___pyx_scope_struct__full_scores = 0; +static PyTypeObject *__pyx_ptype_5kenlm_LanguageModel = 0; static PyObject *__pyx_f_5kenlm_as_str(PyObject *); /*proto*/ #define __Pyx_MODULE_NAME "kenlm" int __pyx_module_is_main_kenlm = 0; @@ -792,8 +792,8 @@ static PyObject *__pyx_pf_5kenlm_13LanguageModel_13__reduce__(struct __pyx_obj_5 static PyObject *__pyx_pf_5kenlm_13LanguageModel_4path___get__(struct __pyx_obj_5kenlm_LanguageModel *__pyx_v_self); /* proto */ static int __pyx_pf_5kenlm_13LanguageModel_4path_2__set__(struct __pyx_obj_5kenlm_LanguageModel *__pyx_v_self, PyObject *__pyx_v_value); /* proto */ static int __pyx_pf_5kenlm_13LanguageModel_4path_4__del__(struct __pyx_obj_5kenlm_LanguageModel *__pyx_v_self); /* proto */ -static PyObject *__pyx_tp_new_5kenlm_LanguageModel(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/ static PyObject *__pyx_tp_new_5kenlm___pyx_scope_struct__full_scores(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/ +static PyObject *__pyx_tp_new_5kenlm_LanguageModel(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/ static char __pyx_k_2[] = "Cannot convert %s to string"; static char __pyx_k_3[] = "\n"; static char __pyx_k_4[] = " "; @@ -1392,7 +1392,7 @@ static PyObject *__pyx_pf_5kenlm_13LanguageModel_4score(struct __pyx_obj_5kenlm_ * cdef State out_state * cdef float total = 0 # <<<<<<<<<<<<<< * for word in words: - * total += self.model.Score(&state, self.vocab.Index(word), &out_state) + * total += self.model.BaseScore(&state, self.vocab.Index(word), &out_state) */ __pyx_v_total = 0.0; @@ -1400,7 +1400,7 @@ static PyObject *__pyx_pf_5kenlm_13LanguageModel_4score(struct __pyx_obj_5kenlm_ * cdef State out_state * cdef float total = 0 * for word in words: # <<<<<<<<<<<<<< - * total += self.model.Score(&state, self.vocab.Index(word), &out_state) + * total += self.model.BaseScore(&state, self.vocab.Index(word), &out_state) * state = out_state */ if (unlikely(((PyObject *)__pyx_v_words) == Py_None)) { @@ -1422,18 +1422,18 @@ static PyObject *__pyx_pf_5kenlm_13LanguageModel_4score(struct __pyx_obj_5kenlm_ /* "kenlm.pyx":39 * cdef float total = 0 * for word in words: - * total += self.model.Score(&state, self.vocab.Index(word), &out_state) # <<<<<<<<<<<<<< + * total += self.model.BaseScore(&state, self.vocab.Index(word), &out_state) # <<<<<<<<<<<<<< * state = out_state - * total += self.model.Score(&state, self.vocab.EndSentence(), &out_state) + * total += self.model.BaseScore(&state, self.vocab.EndSentence(), &out_state) */ __pyx_t_4 = __Pyx_PyObject_AsString(__pyx_v_word); if (unlikely((!__pyx_t_4) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_v_total = (__pyx_v_total + __pyx_v_self->model->Score((&__pyx_v_state), __pyx_v_self->vocab->Index(__pyx_t_4), (&__pyx_v_out_state))); + __pyx_v_total = (__pyx_v_total + __pyx_v_self->model->BaseScore((&__pyx_v_state), __pyx_v_self->vocab->Index(__pyx_t_4), (&__pyx_v_out_state))); /* "kenlm.pyx":40 * for word in words: - * total += self.model.Score(&state, self.vocab.Index(word), &out_state) + * total += self.model.BaseScore(&state, self.vocab.Index(word), &out_state) * state = out_state # <<<<<<<<<<<<<< - * total += self.model.Score(&state, self.vocab.EndSentence(), &out_state) + * total += self.model.BaseScore(&state, self.vocab.EndSentence(), &out_state) * return total */ __pyx_v_state = __pyx_v_out_state; @@ -1441,17 +1441,17 @@ static PyObject *__pyx_pf_5kenlm_13LanguageModel_4score(struct __pyx_obj_5kenlm_ __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "kenlm.pyx":41 - * total += self.model.Score(&state, self.vocab.Index(word), &out_state) + * total += self.model.BaseScore(&state, self.vocab.Index(word), &out_state) * state = out_state - * total += self.model.Score(&state, self.vocab.EndSentence(), &out_state) # <<<<<<<<<<<<<< + * total += self.model.BaseScore(&state, self.vocab.EndSentence(), &out_state) # <<<<<<<<<<<<<< * return total * */ - __pyx_v_total = (__pyx_v_total + __pyx_v_self->model->Score((&__pyx_v_state), __pyx_v_self->vocab->EndSentence(), (&__pyx_v_out_state))); + __pyx_v_total = (__pyx_v_total + __pyx_v_self->model->BaseScore((&__pyx_v_state), __pyx_v_self->vocab->EndSentence(), (&__pyx_v_out_state))); /* "kenlm.pyx":42 * state = out_state - * total += self.model.Score(&state, self.vocab.EndSentence(), &out_state) + * total += self.model.BaseScore(&state, self.vocab.EndSentence(), &out_state) * return total # <<<<<<<<<<<<<< * * def full_scores(self, sentence): @@ -1597,7 +1597,7 @@ static PyObject *__pyx_gb_5kenlm_13LanguageModel_8generator(__pyx_GeneratorObjec * cdef FullScoreReturn ret * cdef float total = 0 # <<<<<<<<<<<<<< * for word in words: - * ret = self.model.FullScore(&state, + * ret = self.model.BaseFullScore(&state, */ __pyx_cur_scope->__pyx_v_total = 0.0; @@ -1605,7 +1605,7 @@ static PyObject *__pyx_gb_5kenlm_13LanguageModel_8generator(__pyx_GeneratorObjec * cdef FullScoreReturn ret * cdef float total = 0 * for word in words: # <<<<<<<<<<<<<< - * ret = self.model.FullScore(&state, + * ret = self.model.BaseFullScore(&state, * self.vocab.Index(word), &out_state) */ if (unlikely(((PyObject *)__pyx_cur_scope->__pyx_v_words) == Py_None)) { @@ -1628,20 +1628,20 @@ static PyObject *__pyx_gb_5kenlm_13LanguageModel_8generator(__pyx_GeneratorObjec /* "kenlm.pyx":53 * for word in words: - * ret = self.model.FullScore(&state, + * ret = self.model.BaseFullScore(&state, * self.vocab.Index(word), &out_state) # <<<<<<<<<<<<<< * yield (ret.prob, ret.ngram_length) * state = out_state */ __pyx_t_4 = __Pyx_PyObject_AsString(__pyx_cur_scope->__pyx_v_word); if (unlikely((!__pyx_t_4) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_cur_scope->__pyx_v_ret = __pyx_cur_scope->__pyx_v_self->model->FullScore((&__pyx_cur_scope->__pyx_v_state), __pyx_cur_scope->__pyx_v_self->vocab->Index(__pyx_t_4), (&__pyx_cur_scope->__pyx_v_out_state)); + __pyx_cur_scope->__pyx_v_ret = __pyx_cur_scope->__pyx_v_self->model->BaseFullScore((&__pyx_cur_scope->__pyx_v_state), __pyx_cur_scope->__pyx_v_self->vocab->Index(__pyx_t_4), (&__pyx_cur_scope->__pyx_v_out_state)); /* "kenlm.pyx":54 - * ret = self.model.FullScore(&state, + * ret = self.model.BaseFullScore(&state, * self.vocab.Index(word), &out_state) * yield (ret.prob, ret.ngram_length) # <<<<<<<<<<<<<< * state = out_state - * ret = self.model.FullScore(&state, + * ret = self.model.BaseFullScore(&state, */ __pyx_t_2 = PyFloat_FromDouble(__pyx_cur_scope->__pyx_v_ret.prob); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); @@ -1676,7 +1676,7 @@ static PyObject *__pyx_gb_5kenlm_13LanguageModel_8generator(__pyx_GeneratorObjec * self.vocab.Index(word), &out_state) * yield (ret.prob, ret.ngram_length) * state = out_state # <<<<<<<<<<<<<< - * ret = self.model.FullScore(&state, + * ret = self.model.BaseFullScore(&state, * self.vocab.EndSentence(), &out_state) */ __pyx_cur_scope->__pyx_v_state = __pyx_cur_scope->__pyx_v_out_state; @@ -1685,15 +1685,15 @@ static PyObject *__pyx_gb_5kenlm_13LanguageModel_8generator(__pyx_GeneratorObjec /* "kenlm.pyx":57 * state = out_state - * ret = self.model.FullScore(&state, + * ret = self.model.BaseFullScore(&state, * self.vocab.EndSentence(), &out_state) # <<<<<<<<<<<<<< * yield (ret.prob, ret.ngram_length) * */ - __pyx_cur_scope->__pyx_v_ret = __pyx_cur_scope->__pyx_v_self->model->FullScore((&__pyx_cur_scope->__pyx_v_state), __pyx_cur_scope->__pyx_v_self->vocab->EndSentence(), (&__pyx_cur_scope->__pyx_v_out_state)); + __pyx_cur_scope->__pyx_v_ret = __pyx_cur_scope->__pyx_v_self->model->BaseFullScore((&__pyx_cur_scope->__pyx_v_state), __pyx_cur_scope->__pyx_v_self->vocab->EndSentence(), (&__pyx_cur_scope->__pyx_v_out_state)); /* "kenlm.pyx":58 - * ret = self.model.FullScore(&state, + * ret = self.model.BaseFullScore(&state, * self.vocab.EndSentence(), &out_state) * yield (ret.prob, ret.ngram_length) # <<<<<<<<<<<<<< * @@ -2047,6 +2047,147 @@ static int __pyx_pf_5kenlm_13LanguageModel_4path_4__del__(struct __pyx_obj_5kenl return __pyx_r; } +static struct __pyx_obj_5kenlm___pyx_scope_struct__full_scores *__pyx_freelist_5kenlm___pyx_scope_struct__full_scores[8]; +static int __pyx_freecount_5kenlm___pyx_scope_struct__full_scores = 0; + +static PyObject *__pyx_tp_new_5kenlm___pyx_scope_struct__full_scores(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { + struct __pyx_obj_5kenlm___pyx_scope_struct__full_scores *p; + PyObject *o; + if (likely((__pyx_freecount_5kenlm___pyx_scope_struct__full_scores > 0) & (t->tp_basicsize == sizeof(struct __pyx_obj_5kenlm___pyx_scope_struct__full_scores)))) { + o = (PyObject*)__pyx_freelist_5kenlm___pyx_scope_struct__full_scores[--__pyx_freecount_5kenlm___pyx_scope_struct__full_scores]; + memset(o, 0, sizeof(struct __pyx_obj_5kenlm___pyx_scope_struct__full_scores)); + PyObject_INIT(o, t); + PyObject_GC_Track(o); + } else { + o = (*t->tp_alloc)(t, 0); + if (unlikely(!o)) return 0; + } + p = ((struct __pyx_obj_5kenlm___pyx_scope_struct__full_scores *)o); + p->__pyx_v_self = 0; + p->__pyx_v_sentence = 0; + p->__pyx_v_word = 0; + p->__pyx_v_words = 0; + p->__pyx_t_0 = 0; + return o; +} + +static void __pyx_tp_dealloc_5kenlm___pyx_scope_struct__full_scores(PyObject *o) { + struct __pyx_obj_5kenlm___pyx_scope_struct__full_scores *p = (struct __pyx_obj_5kenlm___pyx_scope_struct__full_scores *)o; + PyObject_GC_UnTrack(o); + Py_CLEAR(p->__pyx_v_self); + Py_CLEAR(p->__pyx_v_sentence); + Py_CLEAR(p->__pyx_v_word); + Py_CLEAR(p->__pyx_v_words); + Py_CLEAR(p->__pyx_t_0); + if ((__pyx_freecount_5kenlm___pyx_scope_struct__full_scores < 8) & (Py_TYPE(o)->tp_basicsize == sizeof(struct __pyx_obj_5kenlm___pyx_scope_struct__full_scores))) { + __pyx_freelist_5kenlm___pyx_scope_struct__full_scores[__pyx_freecount_5kenlm___pyx_scope_struct__full_scores++] = ((struct __pyx_obj_5kenlm___pyx_scope_struct__full_scores *)o); + } else { + (*Py_TYPE(o)->tp_free)(o); + } +} + +static int __pyx_tp_traverse_5kenlm___pyx_scope_struct__full_scores(PyObject *o, visitproc v, void *a) { + int e; + struct __pyx_obj_5kenlm___pyx_scope_struct__full_scores *p = (struct __pyx_obj_5kenlm___pyx_scope_struct__full_scores *)o; + if (p->__pyx_v_self) { + e = (*v)(((PyObject*)p->__pyx_v_self), a); if (e) return e; + } + if (p->__pyx_v_sentence) { + e = (*v)(p->__pyx_v_sentence, a); if (e) return e; + } + if (p->__pyx_v_word) { + e = (*v)(p->__pyx_v_word, a); if (e) return e; + } + if (p->__pyx_v_words) { + e = (*v)(p->__pyx_v_words, a); if (e) return e; + } + if (p->__pyx_t_0) { + e = (*v)(p->__pyx_t_0, a); if (e) return e; + } + return 0; +} + +static int __pyx_tp_clear_5kenlm___pyx_scope_struct__full_scores(PyObject *o) { + struct __pyx_obj_5kenlm___pyx_scope_struct__full_scores *p = (struct __pyx_obj_5kenlm___pyx_scope_struct__full_scores *)o; + PyObject* tmp; + tmp = ((PyObject*)p->__pyx_v_self); + p->__pyx_v_self = ((struct __pyx_obj_5kenlm_LanguageModel *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_sentence); + p->__pyx_v_sentence = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_word); + p->__pyx_v_word = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_words); + p->__pyx_v_words = ((PyObject*)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_t_0); + p->__pyx_t_0 = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + return 0; +} + +static PyMethodDef __pyx_methods_5kenlm___pyx_scope_struct__full_scores[] = { + {0, 0, 0, 0} +}; + +static PyTypeObject __pyx_type_5kenlm___pyx_scope_struct__full_scores = { + PyVarObject_HEAD_INIT(0, 0) + __Pyx_NAMESTR("kenlm.__pyx_scope_struct__full_scores"), /*tp_name*/ + sizeof(struct __pyx_obj_5kenlm___pyx_scope_struct__full_scores), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_5kenlm___pyx_scope_struct__full_scores, /*tp_dealloc*/ + 0, /*tp_print*/ + 0, /*tp_getattr*/ + 0, /*tp_setattr*/ + #if PY_MAJOR_VERSION < 3 + 0, /*tp_compare*/ + #else + 0, /*reserved*/ + #endif + 0, /*tp_repr*/ + 0, /*tp_as_number*/ + 0, /*tp_as_sequence*/ + 0, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + 0, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ + 0, /*tp_doc*/ + __pyx_tp_traverse_5kenlm___pyx_scope_struct__full_scores, /*tp_traverse*/ + __pyx_tp_clear_5kenlm___pyx_scope_struct__full_scores, /*tp_clear*/ + 0, /*tp_richcompare*/ + 0, /*tp_weaklistoffset*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_5kenlm___pyx_scope_struct__full_scores, /*tp_methods*/ + 0, /*tp_members*/ + 0, /*tp_getset*/ + 0, /*tp_base*/ + 0, /*tp_dict*/ + 0, /*tp_descr_get*/ + 0, /*tp_descr_set*/ + 0, /*tp_dictoffset*/ + 0, /*tp_init*/ + 0, /*tp_alloc*/ + __pyx_tp_new_5kenlm___pyx_scope_struct__full_scores, /*tp_new*/ + 0, /*tp_free*/ + 0, /*tp_is_gc*/ + 0, /*tp_bases*/ + 0, /*tp_mro*/ + 0, /*tp_cache*/ + 0, /*tp_subclasses*/ + 0, /*tp_weaklist*/ + 0, /*tp_del*/ + #if PY_VERSION_HEX >= 0x02060000 + 0, /*tp_version_tag*/ + #endif +}; + static PyObject *__pyx_tp_new_5kenlm_LanguageModel(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { struct __pyx_obj_5kenlm_LanguageModel *p; PyObject *o; @@ -2190,147 +2331,6 @@ static PyTypeObject __pyx_type_5kenlm_LanguageModel = { #endif }; -static struct __pyx_obj_5kenlm___pyx_scope_struct__full_scores *__pyx_freelist_5kenlm___pyx_scope_struct__full_scores[8]; -static int __pyx_freecount_5kenlm___pyx_scope_struct__full_scores = 0; - -static PyObject *__pyx_tp_new_5kenlm___pyx_scope_struct__full_scores(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { - struct __pyx_obj_5kenlm___pyx_scope_struct__full_scores *p; - PyObject *o; - if (likely((__pyx_freecount_5kenlm___pyx_scope_struct__full_scores > 0) & (t->tp_basicsize == sizeof(struct __pyx_obj_5kenlm___pyx_scope_struct__full_scores)))) { - o = (PyObject*)__pyx_freelist_5kenlm___pyx_scope_struct__full_scores[--__pyx_freecount_5kenlm___pyx_scope_struct__full_scores]; - memset(o, 0, sizeof(struct __pyx_obj_5kenlm___pyx_scope_struct__full_scores)); - PyObject_INIT(o, t); - PyObject_GC_Track(o); - } else { - o = (*t->tp_alloc)(t, 0); - if (unlikely(!o)) return 0; - } - p = ((struct __pyx_obj_5kenlm___pyx_scope_struct__full_scores *)o); - p->__pyx_v_self = 0; - p->__pyx_v_sentence = 0; - p->__pyx_v_word = 0; - p->__pyx_v_words = 0; - p->__pyx_t_0 = 0; - return o; -} - -static void __pyx_tp_dealloc_5kenlm___pyx_scope_struct__full_scores(PyObject *o) { - struct __pyx_obj_5kenlm___pyx_scope_struct__full_scores *p = (struct __pyx_obj_5kenlm___pyx_scope_struct__full_scores *)o; - PyObject_GC_UnTrack(o); - Py_CLEAR(p->__pyx_v_self); - Py_CLEAR(p->__pyx_v_sentence); - Py_CLEAR(p->__pyx_v_word); - Py_CLEAR(p->__pyx_v_words); - Py_CLEAR(p->__pyx_t_0); - if ((__pyx_freecount_5kenlm___pyx_scope_struct__full_scores < 8) & (Py_TYPE(o)->tp_basicsize == sizeof(struct __pyx_obj_5kenlm___pyx_scope_struct__full_scores))) { - __pyx_freelist_5kenlm___pyx_scope_struct__full_scores[__pyx_freecount_5kenlm___pyx_scope_struct__full_scores++] = ((struct __pyx_obj_5kenlm___pyx_scope_struct__full_scores *)o); - } else { - (*Py_TYPE(o)->tp_free)(o); - } -} - -static int __pyx_tp_traverse_5kenlm___pyx_scope_struct__full_scores(PyObject *o, visitproc v, void *a) { - int e; - struct __pyx_obj_5kenlm___pyx_scope_struct__full_scores *p = (struct __pyx_obj_5kenlm___pyx_scope_struct__full_scores *)o; - if (p->__pyx_v_self) { - e = (*v)(((PyObject*)p->__pyx_v_self), a); if (e) return e; - } - if (p->__pyx_v_sentence) { - e = (*v)(p->__pyx_v_sentence, a); if (e) return e; - } - if (p->__pyx_v_word) { - e = (*v)(p->__pyx_v_word, a); if (e) return e; - } - if (p->__pyx_v_words) { - e = (*v)(p->__pyx_v_words, a); if (e) return e; - } - if (p->__pyx_t_0) { - e = (*v)(p->__pyx_t_0, a); if (e) return e; - } - return 0; -} - -static int __pyx_tp_clear_5kenlm___pyx_scope_struct__full_scores(PyObject *o) { - struct __pyx_obj_5kenlm___pyx_scope_struct__full_scores *p = (struct __pyx_obj_5kenlm___pyx_scope_struct__full_scores *)o; - PyObject* tmp; - tmp = ((PyObject*)p->__pyx_v_self); - p->__pyx_v_self = ((struct __pyx_obj_5kenlm_LanguageModel *)Py_None); Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->__pyx_v_sentence); - p->__pyx_v_sentence = Py_None; Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->__pyx_v_word); - p->__pyx_v_word = Py_None; Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->__pyx_v_words); - p->__pyx_v_words = ((PyObject*)Py_None); Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->__pyx_t_0); - p->__pyx_t_0 = Py_None; Py_INCREF(Py_None); - Py_XDECREF(tmp); - return 0; -} - -static PyMethodDef __pyx_methods_5kenlm___pyx_scope_struct__full_scores[] = { - {0, 0, 0, 0} -}; - -static PyTypeObject __pyx_type_5kenlm___pyx_scope_struct__full_scores = { - PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("kenlm.__pyx_scope_struct__full_scores"), /*tp_name*/ - sizeof(struct __pyx_obj_5kenlm___pyx_scope_struct__full_scores), /*tp_basicsize*/ - 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5kenlm___pyx_scope_struct__full_scores, /*tp_dealloc*/ - 0, /*tp_print*/ - 0, /*tp_getattr*/ - 0, /*tp_setattr*/ - #if PY_MAJOR_VERSION < 3 - 0, /*tp_compare*/ - #else - 0, /*reserved*/ - #endif - 0, /*tp_repr*/ - 0, /*tp_as_number*/ - 0, /*tp_as_sequence*/ - 0, /*tp_as_mapping*/ - 0, /*tp_hash*/ - 0, /*tp_call*/ - 0, /*tp_str*/ - 0, /*tp_getattro*/ - 0, /*tp_setattro*/ - 0, /*tp_as_buffer*/ - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ - 0, /*tp_doc*/ - __pyx_tp_traverse_5kenlm___pyx_scope_struct__full_scores, /*tp_traverse*/ - __pyx_tp_clear_5kenlm___pyx_scope_struct__full_scores, /*tp_clear*/ - 0, /*tp_richcompare*/ - 0, /*tp_weaklistoffset*/ - 0, /*tp_iter*/ - 0, /*tp_iternext*/ - __pyx_methods_5kenlm___pyx_scope_struct__full_scores, /*tp_methods*/ - 0, /*tp_members*/ - 0, /*tp_getset*/ - 0, /*tp_base*/ - 0, /*tp_dict*/ - 0, /*tp_descr_get*/ - 0, /*tp_descr_set*/ - 0, /*tp_dictoffset*/ - 0, /*tp_init*/ - 0, /*tp_alloc*/ - __pyx_tp_new_5kenlm___pyx_scope_struct__full_scores, /*tp_new*/ - 0, /*tp_free*/ - 0, /*tp_is_gc*/ - 0, /*tp_bases*/ - 0, /*tp_mro*/ - 0, /*tp_cache*/ - 0, /*tp_subclasses*/ - 0, /*tp_weaklist*/ - 0, /*tp_del*/ - #if PY_VERSION_HEX >= 0x02060000 - 0, /*tp_version_tag*/ - #endif -}; - static PyMethodDef __pyx_methods[] = { {0, 0, 0, 0} }; @@ -2508,11 +2508,11 @@ PyMODINIT_FUNC PyInit_kenlm(void) /*--- Variable export code ---*/ /*--- Function export code ---*/ /*--- Type init code ---*/ + if (PyType_Ready(&__pyx_type_5kenlm___pyx_scope_struct__full_scores) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_5kenlm___pyx_scope_struct__full_scores = &__pyx_type_5kenlm___pyx_scope_struct__full_scores; if (PyType_Ready(&__pyx_type_5kenlm_LanguageModel) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 10; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (__Pyx_SetAttrString(__pyx_m, "LanguageModel", (PyObject *)&__pyx_type_5kenlm_LanguageModel) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 10; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_5kenlm_LanguageModel = &__pyx_type_5kenlm_LanguageModel; - if (PyType_Ready(&__pyx_type_5kenlm___pyx_scope_struct__full_scores) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_ptype_5kenlm___pyx_scope_struct__full_scores = &__pyx_type_5kenlm___pyx_scope_struct__full_scores; /*--- Type import code ---*/ /*--- Variable import code ---*/ /*--- Function import code ---*/ diff --git a/python/kenlm.pxd b/python/kenlm.pxd index 9a397f3..7d68fc4 100644 --- a/python/kenlm.pxd +++ b/python/kenlm.pxd @@ -24,8 +24,8 @@ cdef extern from "lm/virtual_interface.hh" namespace "lm::base": void NullContextWrite(void *) unsigned int Order() const_Vocabulary& BaseVocabulary() - float Score(void *in_state, WordIndex new_word, void *out_state) - FullScoreReturn FullScore(void *in_state, WordIndex new_word, void *out_state) + float BaseScore(void *in_state, WordIndex new_word, void *out_state) + FullScoreReturn BaseFullScore(void *in_state, WordIndex new_word, void *out_state) cdef extern from "lm/model.hh" namespace "lm::ngram": cdef Model *LoadVirtual(char *) except + diff --git a/python/kenlm.pyx b/python/kenlm.pyx index 7f965d4..eb45169 100644 --- a/python/kenlm.pyx +++ b/python/kenlm.pyx @@ -36,9 +36,9 @@ cdef class LanguageModel: cdef State out_state cdef float total = 0 for word in words: - total += self.model.Score(&state, self.vocab.Index(word), &out_state) + total += self.model.BaseScore(&state, self.vocab.Index(word), &out_state) state = out_state - total += self.model.Score(&state, self.vocab.EndSentence(), &out_state) + total += self.model.BaseScore(&state, self.vocab.EndSentence(), &out_state) return total def full_scores(self, sentence): @@ -49,11 +49,11 @@ cdef class LanguageModel: cdef FullScoreReturn ret cdef float total = 0 for word in words: - ret = self.model.FullScore(&state, + ret = self.model.BaseFullScore(&state, self.vocab.Index(word), &out_state) yield (ret.prob, ret.ngram_length) state = out_state - ret = self.model.FullScore(&state, + ret = self.model.BaseFullScore(&state, self.vocab.EndSentence(), &out_state) yield (ret.prob, ret.ngram_length) |