Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/kpu/kenlm.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorKenneth Heafield <github@kheafield.com>2016-06-27 13:06:24 +0300
committerKenneth Heafield <github@kheafield.com>2016-06-27 13:06:24 +0300
commit80a20eb06b1c12d9cbc9a5c6c2f0a0cdcba81e1f (patch)
tree4b36b2c0face5a67ff3c2cdc7b99639919901e21 /python
parentff50c09f2fc89d69f17dc4f57fd5f9a0b6c0290f (diff)
Update cython code
Diffstat (limited to 'python')
-rw-r--r--python/kenlm.cpp560
-rw-r--r--python/kenlm.pyx2
2 files changed, 357 insertions, 205 deletions
diff --git a/python/kenlm.cpp b/python/kenlm.cpp
index b1f4340..14e9799 100644
--- a/python/kenlm.cpp
+++ b/python/kenlm.cpp
@@ -503,8 +503,8 @@ struct __pyx_obj_5kenlm_Model {
};
-/* "kenlm.pyx":144
- * return total
+/* "kenlm.pyx":190
+ * return 10.0**(-self.score(sentence) / words)
*
* def full_scores(self, sentence, bos = True, eos = True): # <<<<<<<<<<<<<<
* """
@@ -803,14 +803,15 @@ static int __pyx_pf_5kenlm_5Model___init__(struct __pyx_obj_5kenlm_Model *__pyx_
static void __pyx_pf_5kenlm_5Model_2__dealloc__(struct __pyx_obj_5kenlm_Model *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5kenlm_5Model_5order___get__(struct __pyx_obj_5kenlm_Model *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5kenlm_5Model_4score(struct __pyx_obj_5kenlm_Model *__pyx_v_self, PyObject *__pyx_v_sentence, PyObject *__pyx_v_bos, PyObject *__pyx_v_eos); /* proto */
-static PyObject *__pyx_pf_5kenlm_5Model_6full_scores(struct __pyx_obj_5kenlm_Model *__pyx_v_self, PyObject *__pyx_v_sentence, PyObject *__pyx_v_bos, PyObject *__pyx_v_eos); /* proto */
-static PyObject *__pyx_pf_5kenlm_5Model_9BeginSentenceWrite(struct __pyx_obj_5kenlm_Model *__pyx_v_self, struct __pyx_obj_5kenlm_State *__pyx_v_state); /* proto */
-static PyObject *__pyx_pf_5kenlm_5Model_11NullContextWrite(struct __pyx_obj_5kenlm_Model *__pyx_v_self, struct __pyx_obj_5kenlm_State *__pyx_v_state); /* proto */
-static PyObject *__pyx_pf_5kenlm_5Model_13BaseScore(struct __pyx_obj_5kenlm_Model *__pyx_v_self, struct __pyx_obj_5kenlm_State *__pyx_v_in_state, PyObject *__pyx_v_word, struct __pyx_obj_5kenlm_State *__pyx_v_out_state); /* proto */
-static PyObject *__pyx_pf_5kenlm_5Model_15BaseFullScore(struct __pyx_obj_5kenlm_Model *__pyx_v_self, struct __pyx_obj_5kenlm_State *__pyx_v_in_state, PyObject *__pyx_v_word, struct __pyx_obj_5kenlm_State *__pyx_v_out_state); /* proto */
-static int __pyx_pf_5kenlm_5Model_17__contains__(struct __pyx_obj_5kenlm_Model *__pyx_v_self, PyObject *__pyx_v_word); /* proto */
-static PyObject *__pyx_pf_5kenlm_5Model_19__repr__(struct __pyx_obj_5kenlm_Model *__pyx_v_self); /* proto */
-static PyObject *__pyx_pf_5kenlm_5Model_21__reduce__(struct __pyx_obj_5kenlm_Model *__pyx_v_self); /* proto */
+static PyObject *__pyx_pf_5kenlm_5Model_6perplexity(struct __pyx_obj_5kenlm_Model *__pyx_v_self, PyObject *__pyx_v_sentence); /* proto */
+static PyObject *__pyx_pf_5kenlm_5Model_8full_scores(struct __pyx_obj_5kenlm_Model *__pyx_v_self, PyObject *__pyx_v_sentence, PyObject *__pyx_v_bos, PyObject *__pyx_v_eos); /* proto */
+static PyObject *__pyx_pf_5kenlm_5Model_11BeginSentenceWrite(struct __pyx_obj_5kenlm_Model *__pyx_v_self, struct __pyx_obj_5kenlm_State *__pyx_v_state); /* proto */
+static PyObject *__pyx_pf_5kenlm_5Model_13NullContextWrite(struct __pyx_obj_5kenlm_Model *__pyx_v_self, struct __pyx_obj_5kenlm_State *__pyx_v_state); /* proto */
+static PyObject *__pyx_pf_5kenlm_5Model_15BaseScore(struct __pyx_obj_5kenlm_Model *__pyx_v_self, struct __pyx_obj_5kenlm_State *__pyx_v_in_state, PyObject *__pyx_v_word, struct __pyx_obj_5kenlm_State *__pyx_v_out_state); /* proto */
+static PyObject *__pyx_pf_5kenlm_5Model_17BaseFullScore(struct __pyx_obj_5kenlm_Model *__pyx_v_self, struct __pyx_obj_5kenlm_State *__pyx_v_in_state, PyObject *__pyx_v_word, struct __pyx_obj_5kenlm_State *__pyx_v_out_state); /* proto */
+static int __pyx_pf_5kenlm_5Model_19__contains__(struct __pyx_obj_5kenlm_Model *__pyx_v_self, PyObject *__pyx_v_word); /* proto */
+static PyObject *__pyx_pf_5kenlm_5Model_21__repr__(struct __pyx_obj_5kenlm_Model *__pyx_v_self); /* proto */
+static PyObject *__pyx_pf_5kenlm_5Model_23__reduce__(struct __pyx_obj_5kenlm_Model *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5kenlm_5Model_4path___get__(struct __pyx_obj_5kenlm_Model *__pyx_v_self); /* proto */
static int __pyx_pf_5kenlm_5Model_4path_2__set__(struct __pyx_obj_5kenlm_Model *__pyx_v_self, PyObject *__pyx_v_value); /* proto */
static int __pyx_pf_5kenlm_5Model_4path_4__del__(struct __pyx_obj_5kenlm_Model *__pyx_v_self); /* proto */
@@ -839,6 +840,7 @@ static char __pyx_k_word[] = "word";
static char __pyx_k_class[] = "__class__";
static char __pyx_k_close[] = "close";
static char __pyx_k_kenlm[] = "_kenlm";
+static char __pyx_k_score[] = "score";
static char __pyx_k_split[] = "split";
static char __pyx_k_throw[] = "throw";
static char __pyx_k_config[] = "config";
@@ -920,6 +922,7 @@ static PyObject *__pyx_n_s_path;
static PyObject *__pyx_n_s_prepare;
static PyObject *__pyx_n_s_qualname;
static PyObject *__pyx_n_s_replace;
+static PyObject *__pyx_n_s_score;
static PyObject *__pyx_n_s_send;
static PyObject *__pyx_n_s_sentence;
static PyObject *__pyx_n_s_split;
@@ -927,6 +930,7 @@ static PyObject *__pyx_n_s_test;
static PyObject *__pyx_n_s_throw;
static PyObject *__pyx_n_s_utf8;
static PyObject *__pyx_n_s_word;
+static PyObject *__pyx_float_10_0;
static struct __pyx_obj_5kenlm_Config *__pyx_k__2;
static PyObject *__pyx_tuple_;
static PyObject *__pyx_tuple__5;
@@ -2395,12 +2399,13 @@ static PyObject *__pyx_pf_5kenlm_5Model_5order___get__(struct __pyx_obj_5kenlm_M
* return self.model.Order()
*
* def score(self, sentence, bos = True, eos = True): # <<<<<<<<<<<<<<
- * cdef list words = as_str(sentence).split()
- * cdef _kenlm.State state
+ * """
+ * Return the log10 probability of a string. By default, the string is
*/
/* Python wrapper */
static PyObject *__pyx_pw_5kenlm_5Model_5score(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static char __pyx_doc_5kenlm_5Model_4score[] = "\n Return the log10 probability of a string. By default, the string is\n treated as a sentence. \n return log10 p(sentence </s> | <s>)\n\n If you do not want to condition on the beginning of sentence, pass\n bos = False\n Never include <s> as part of the string. That would be predicting the\n beginning of sentence. Language models are only supposed to condition\n on it as context.\n\n Similarly, the end of sentence token </s> can be omitted with\n eos = False\n Since language models explicitly predict </s>, it can be part of the\n string.\n\n Examples:\n\n #Good: returns log10 p(this is a sentence . </s> | <s>)\n model.score(\"this is a sentence .\")\n #Good: same as the above but more explicit\n model.score(\"this is a sentence .\", bos = True, eos = True)\n\n #Bad: never include <s>\n model.score(\"<s> this is a sentence\")\n #Bad: never include <s>, even if bos = False.\n model.score(\"<s> this is a sentence\", bos = False)\n\n #Good: returns log10 p(a fragment)\n model.score(\"a fragment\", bos = False, eos = False)\n\n #Good: returns log10 p(a fragment </s>)\n model.score(\"a fragment\", bos = False, eos = True)\n\n #Ok, but bad practice: returns log10 p(a fragment </s>)\n #Unlike <s>, the end of sentence token </s> can appear explicitly.\n model.score(\"a fragment </s>\", bos = False, eos = False)\n ";
static PyObject *__pyx_pw_5kenlm_5Model_5score(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
PyObject *__pyx_v_sentence = 0;
PyObject *__pyx_v_bos = 0;
@@ -2492,16 +2497,16 @@ static PyObject *__pyx_pf_5kenlm_5Model_4score(struct __pyx_obj_5kenlm_Model *__
int __pyx_clineno = 0;
__Pyx_RefNannySetupContext("score", 0);
- /* "kenlm.pyx":129
- *
- * def score(self, sentence, bos = True, eos = True):
+ /* "kenlm.pyx":167
+ * model.score("a fragment </s>", bos = False, eos = False)
+ * """
* cdef list words = as_str(sentence).split() # <<<<<<<<<<<<<<
* cdef _kenlm.State state
* if bos:
*/
- __pyx_t_2 = __pyx_f_5kenlm_as_str(__pyx_v_sentence); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 129; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = __pyx_f_5kenlm_as_str(__pyx_v_sentence); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_split); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 129; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_split); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_3);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
__pyx_t_2 = NULL;
@@ -2515,28 +2520,28 @@ static PyObject *__pyx_pf_5kenlm_5Model_4score(struct __pyx_obj_5kenlm_Model *__
}
}
if (__pyx_t_2) {
- __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 129; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
} else {
- __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 129; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
}
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- if (!(likely(PyList_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "list", Py_TYPE(__pyx_t_1)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 129; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (!(likely(PyList_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "list", Py_TYPE(__pyx_t_1)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__pyx_v_words = ((PyObject*)__pyx_t_1);
__pyx_t_1 = 0;
- /* "kenlm.pyx":131
+ /* "kenlm.pyx":169
* cdef list words = as_str(sentence).split()
* cdef _kenlm.State state
* if bos: # <<<<<<<<<<<<<<
* self.model.BeginSentenceWrite(&state)
* else:
*/
- __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_v_bos); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 131; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_v_bos); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 169; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
if (__pyx_t_4) {
- /* "kenlm.pyx":132
+ /* "kenlm.pyx":170
* cdef _kenlm.State state
* if bos:
* self.model.BeginSentenceWrite(&state) # <<<<<<<<<<<<<<
@@ -2548,7 +2553,7 @@ static PyObject *__pyx_pf_5kenlm_5Model_4score(struct __pyx_obj_5kenlm_Model *__
}
/*else*/ {
- /* "kenlm.pyx":134
+ /* "kenlm.pyx":172
* self.model.BeginSentenceWrite(&state)
* else:
* self.model.NullContextWrite(&state) # <<<<<<<<<<<<<<
@@ -2559,7 +2564,7 @@ static PyObject *__pyx_pf_5kenlm_5Model_4score(struct __pyx_obj_5kenlm_Model *__
}
__pyx_L3:;
- /* "kenlm.pyx":136
+ /* "kenlm.pyx":174
* self.model.NullContextWrite(&state)
* cdef _kenlm.State out_state
* cdef float total = 0 # <<<<<<<<<<<<<<
@@ -2568,7 +2573,7 @@ static PyObject *__pyx_pf_5kenlm_5Model_4score(struct __pyx_obj_5kenlm_Model *__
*/
__pyx_v_total = 0.0;
- /* "kenlm.pyx":137
+ /* "kenlm.pyx":175
* cdef _kenlm.State out_state
* cdef float total = 0
* for word in words: # <<<<<<<<<<<<<<
@@ -2577,30 +2582,30 @@ static PyObject *__pyx_pf_5kenlm_5Model_4score(struct __pyx_obj_5kenlm_Model *__
*/
if (unlikely(__pyx_v_words == Py_None)) {
PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 137; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
}
__pyx_t_1 = __pyx_v_words; __Pyx_INCREF(__pyx_t_1); __pyx_t_5 = 0;
for (;;) {
if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_1)) break;
#if CYTHON_COMPILING_IN_CPYTHON
- __pyx_t_3 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_5); __Pyx_INCREF(__pyx_t_3); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 137; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_5); __Pyx_INCREF(__pyx_t_3); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
#else
- __pyx_t_3 = PySequence_ITEM(__pyx_t_1, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 137; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = PySequence_ITEM(__pyx_t_1, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
#endif
__Pyx_XDECREF_SET(__pyx_v_word, __pyx_t_3);
__pyx_t_3 = 0;
- /* "kenlm.pyx":138
+ /* "kenlm.pyx":176
* cdef float total = 0
* for word in words:
* total += self.model.BaseScore(&state, self.vocab.Index(word), &out_state) # <<<<<<<<<<<<<<
* state = out_state
* if eos:
*/
- __pyx_t_6 = __Pyx_PyObject_AsString(__pyx_v_word); if (unlikely((!__pyx_t_6) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 138; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_6 = __Pyx_PyObject_AsString(__pyx_v_word); if (unlikely((!__pyx_t_6) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 176; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__pyx_v_total = (__pyx_v_total + __pyx_v_self->model->BaseScore((&__pyx_v_state), __pyx_v_self->vocab->Index(__pyx_t_6), (&__pyx_v_out_state)));
- /* "kenlm.pyx":139
+ /* "kenlm.pyx":177
* for word in words:
* total += self.model.BaseScore(&state, self.vocab.Index(word), &out_state)
* state = out_state # <<<<<<<<<<<<<<
@@ -2609,7 +2614,7 @@ static PyObject *__pyx_pf_5kenlm_5Model_4score(struct __pyx_obj_5kenlm_Model *__
*/
__pyx_v_state = __pyx_v_out_state;
- /* "kenlm.pyx":137
+ /* "kenlm.pyx":175
* cdef _kenlm.State out_state
* cdef float total = 0
* for word in words: # <<<<<<<<<<<<<<
@@ -2619,17 +2624,17 @@ static PyObject *__pyx_pf_5kenlm_5Model_4score(struct __pyx_obj_5kenlm_Model *__
}
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
- /* "kenlm.pyx":140
+ /* "kenlm.pyx":178
* total += self.model.BaseScore(&state, self.vocab.Index(word), &out_state)
* state = out_state
* if eos: # <<<<<<<<<<<<<<
* total += self.model.BaseScore(&state, self.vocab.EndSentence(), &out_state)
* return total
*/
- __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_v_eos); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 140; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_v_eos); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 178; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
if (__pyx_t_4) {
- /* "kenlm.pyx":141
+ /* "kenlm.pyx":179
* state = out_state
* if eos:
* total += self.model.BaseScore(&state, self.vocab.EndSentence(), &out_state) # <<<<<<<<<<<<<<
@@ -2641,15 +2646,15 @@ static PyObject *__pyx_pf_5kenlm_5Model_4score(struct __pyx_obj_5kenlm_Model *__
}
__pyx_L6:;
- /* "kenlm.pyx":142
+ /* "kenlm.pyx":180
* if eos:
* total += self.model.BaseScore(&state, self.vocab.EndSentence(), &out_state)
* return total # <<<<<<<<<<<<<<
*
- * def full_scores(self, sentence, bos = True, eos = True):
+ * def perplexity(self, sentence):
*/
__Pyx_XDECREF(__pyx_r);
- __pyx_t_1 = PyFloat_FromDouble(__pyx_v_total); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_1 = PyFloat_FromDouble(__pyx_v_total); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 180; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
__pyx_r = __pyx_t_1;
__pyx_t_1 = 0;
@@ -2659,8 +2664,8 @@ static PyObject *__pyx_pf_5kenlm_5Model_4score(struct __pyx_obj_5kenlm_Model *__
* return self.model.Order()
*
* def score(self, sentence, bos = True, eos = True): # <<<<<<<<<<<<<<
- * cdef list words = as_str(sentence).split()
- * cdef _kenlm.State state
+ * """
+ * Return the log10 probability of a string. By default, the string is
*/
/* function exit code */
@@ -2677,20 +2682,164 @@ static PyObject *__pyx_pf_5kenlm_5Model_4score(struct __pyx_obj_5kenlm_Model *__
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
-static PyObject *__pyx_gb_5kenlm_5Model_8generator(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */
-/* "kenlm.pyx":144
+/* "kenlm.pyx":182
* return total
*
+ * def perplexity(self, sentence): # <<<<<<<<<<<<<<
+ * """
+ * Compute perplexity of a sentence.
+ */
+
+/* Python wrapper */
+static PyObject *__pyx_pw_5kenlm_5Model_7perplexity(PyObject *__pyx_v_self, PyObject *__pyx_v_sentence); /*proto*/
+static char __pyx_doc_5kenlm_5Model_6perplexity[] = "\n Compute perplexity of a sentence.\n @param sentence One full sentence to score. Do not include <s> or </s>.\n ";
+static PyObject *__pyx_pw_5kenlm_5Model_7perplexity(PyObject *__pyx_v_self, PyObject *__pyx_v_sentence) {
+ PyObject *__pyx_r = 0;
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("perplexity (wrapper)", 0);
+ __pyx_r = __pyx_pf_5kenlm_5Model_6perplexity(((struct __pyx_obj_5kenlm_Model *)__pyx_v_self), ((PyObject *)__pyx_v_sentence));
+
+ /* function exit code */
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+static PyObject *__pyx_pf_5kenlm_5Model_6perplexity(struct __pyx_obj_5kenlm_Model *__pyx_v_self, PyObject *__pyx_v_sentence) {
+ PyObject *__pyx_v_words = NULL;
+ PyObject *__pyx_r = NULL;
+ __Pyx_RefNannyDeclarations
+ PyObject *__pyx_t_1 = NULL;
+ PyObject *__pyx_t_2 = NULL;
+ PyObject *__pyx_t_3 = NULL;
+ Py_ssize_t __pyx_t_4;
+ PyObject *__pyx_t_5 = NULL;
+ int __pyx_lineno = 0;
+ const char *__pyx_filename = NULL;
+ int __pyx_clineno = 0;
+ __Pyx_RefNannySetupContext("perplexity", 0);
+
+ /* "kenlm.pyx":187
+ * @param sentence One full sentence to score. Do not include <s> or </s>.
+ * """
+ * words = len(as_str(sentence).split()) + 1 # For </s> # <<<<<<<<<<<<<<
+ * return 10.0**(-self.score(sentence) / words)
+ *
+ */
+ __pyx_t_2 = __pyx_f_5kenlm_as_str(__pyx_v_sentence); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 187; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_split); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 187; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ __pyx_t_2 = NULL;
+ if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_3))) {
+ __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
+ if (likely(__pyx_t_2)) {
+ PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
+ __Pyx_INCREF(__pyx_t_2);
+ __Pyx_INCREF(function);
+ __Pyx_DECREF_SET(__pyx_t_3, function);
+ }
+ }
+ if (__pyx_t_2) {
+ __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 187; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ } else {
+ __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 187; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ }
+ __Pyx_GOTREF(__pyx_t_1);
+ __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+ __pyx_t_4 = PyObject_Length(__pyx_t_1); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 187; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+ __pyx_t_1 = PyInt_FromSsize_t((__pyx_t_4 + 1)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 187; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_1);
+ __pyx_v_words = __pyx_t_1;
+ __pyx_t_1 = 0;
+
+ /* "kenlm.pyx":188
+ * """
+ * words = len(as_str(sentence).split()) + 1 # For </s>
+ * return 10.0**(-self.score(sentence) / words) # <<<<<<<<<<<<<<
+ *
+ * def full_scores(self, sentence, bos = True, eos = True):
+ */
+ __Pyx_XDECREF(__pyx_r);
+ __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_score); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 188; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_3);
+ __pyx_t_2 = NULL;
+ if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_3))) {
+ __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
+ if (likely(__pyx_t_2)) {
+ PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
+ __Pyx_INCREF(__pyx_t_2);
+ __Pyx_INCREF(function);
+ __Pyx_DECREF_SET(__pyx_t_3, function);
+ }
+ }
+ if (!__pyx_t_2) {
+ __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_sentence); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 188; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_1);
+ } else {
+ __pyx_t_5 = PyTuple_New(1+1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 188; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_5);
+ PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2); __Pyx_GIVEREF(__pyx_t_2); __pyx_t_2 = NULL;
+ __Pyx_INCREF(__pyx_v_sentence);
+ PyTuple_SET_ITEM(__pyx_t_5, 0+1, __pyx_v_sentence);
+ __Pyx_GIVEREF(__pyx_v_sentence);
+ __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 188; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_1);
+ __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+ }
+ __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+ __pyx_t_3 = PyNumber_Negative(__pyx_t_1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 188; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+ __pyx_t_1 = __Pyx_PyNumber_Divide(__pyx_t_3, __pyx_v_words); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 188; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_1);
+ __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+ __pyx_t_3 = PyNumber_Power(__pyx_float_10_0, __pyx_t_1, Py_None); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 188; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+ __pyx_r = __pyx_t_3;
+ __pyx_t_3 = 0;
+ goto __pyx_L0;
+
+ /* "kenlm.pyx":182
+ * return total
+ *
+ * def perplexity(self, sentence): # <<<<<<<<<<<<<<
+ * """
+ * Compute perplexity of a sentence.
+ */
+
+ /* function exit code */
+ __pyx_L1_error:;
+ __Pyx_XDECREF(__pyx_t_1);
+ __Pyx_XDECREF(__pyx_t_2);
+ __Pyx_XDECREF(__pyx_t_3);
+ __Pyx_XDECREF(__pyx_t_5);
+ __Pyx_AddTraceback("kenlm.Model.perplexity", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_r = NULL;
+ __pyx_L0:;
+ __Pyx_XDECREF(__pyx_v_words);
+ __Pyx_XGIVEREF(__pyx_r);
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+static PyObject *__pyx_gb_5kenlm_5Model_10generator(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */
+
+/* "kenlm.pyx":190
+ * return 10.0**(-self.score(sentence) / words)
+ *
* def full_scores(self, sentence, bos = True, eos = True): # <<<<<<<<<<<<<<
* """
* full_scores(sentence, bos = True, eos = Ture) -> generate full scores (prob, ngram length, oov)
*/
/* Python wrapper */
-static PyObject *__pyx_pw_5kenlm_5Model_7full_scores(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
-static char __pyx_doc_5kenlm_5Model_6full_scores[] = "\n full_scores(sentence, bos = True, eos = Ture) -> generate full scores (prob, ngram length, oov)\n @param sentence is a string (do not use boundary symbols)\n @param bos should kenlm add a bos state\n @param eos should kenlm add an eos state\n ";
-static PyObject *__pyx_pw_5kenlm_5Model_7full_scores(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+static PyObject *__pyx_pw_5kenlm_5Model_9full_scores(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static char __pyx_doc_5kenlm_5Model_8full_scores[] = "\n full_scores(sentence, bos = True, eos = Ture) -> generate full scores (prob, ngram length, oov)\n @param sentence is a string (do not use boundary symbols)\n @param bos should kenlm add a bos state\n @param eos should kenlm add an eos state\n ";
+static PyObject *__pyx_pw_5kenlm_5Model_9full_scores(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
PyObject *__pyx_v_sentence = 0;
PyObject *__pyx_v_bos = 0;
PyObject *__pyx_v_eos = 0;
@@ -2732,7 +2881,7 @@ static PyObject *__pyx_pw_5kenlm_5Model_7full_scores(PyObject *__pyx_v_self, PyO
}
}
if (unlikely(kw_args > 0)) {
- if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "full_scores") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 144; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "full_scores") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 190; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
}
} else {
switch (PyTuple_GET_SIZE(__pyx_args)) {
@@ -2749,20 +2898,20 @@ static PyObject *__pyx_pw_5kenlm_5Model_7full_scores(PyObject *__pyx_v_self, PyO
}
goto __pyx_L4_argument_unpacking_done;
__pyx_L5_argtuple_error:;
- __Pyx_RaiseArgtupleInvalid("full_scores", 0, 1, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 144; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ __Pyx_RaiseArgtupleInvalid("full_scores", 0, 1, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 190; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
__pyx_L3_error:;
__Pyx_AddTraceback("kenlm.Model.full_scores", __pyx_clineno, __pyx_lineno, __pyx_filename);
__Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
- __pyx_r = __pyx_pf_5kenlm_5Model_6full_scores(((struct __pyx_obj_5kenlm_Model *)__pyx_v_self), __pyx_v_sentence, __pyx_v_bos, __pyx_v_eos);
+ __pyx_r = __pyx_pf_5kenlm_5Model_8full_scores(((struct __pyx_obj_5kenlm_Model *)__pyx_v_self), __pyx_v_sentence, __pyx_v_bos, __pyx_v_eos);
/* function exit code */
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
-static PyObject *__pyx_pf_5kenlm_5Model_6full_scores(struct __pyx_obj_5kenlm_Model *__pyx_v_self, PyObject *__pyx_v_sentence, PyObject *__pyx_v_bos, PyObject *__pyx_v_eos) {
+static PyObject *__pyx_pf_5kenlm_5Model_8full_scores(struct __pyx_obj_5kenlm_Model *__pyx_v_self, PyObject *__pyx_v_sentence, PyObject *__pyx_v_bos, PyObject *__pyx_v_eos) {
struct __pyx_obj_5kenlm___pyx_scope_struct__full_scores *__pyx_cur_scope;
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
@@ -2789,7 +2938,7 @@ static PyObject *__pyx_pf_5kenlm_5Model_6full_scores(struct __pyx_obj_5kenlm_Mod
__Pyx_INCREF(__pyx_cur_scope->__pyx_v_eos);
__Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_eos);
{
- __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5kenlm_5Model_8generator, (PyObject *) __pyx_cur_scope, __pyx_n_s_full_scores, __pyx_n_s_Model_full_scores); if (unlikely(!gen)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 144; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5kenlm_5Model_10generator, (PyObject *) __pyx_cur_scope, __pyx_n_s_full_scores, __pyx_n_s_Model_full_scores); if (unlikely(!gen)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 190; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(__pyx_cur_scope);
__Pyx_RefNannyFinishContext();
return (PyObject *) gen;
@@ -2805,7 +2954,7 @@ static PyObject *__pyx_pf_5kenlm_5Model_6full_scores(struct __pyx_obj_5kenlm_Mod
return __pyx_r;
}
-static PyObject *__pyx_gb_5kenlm_5Model_8generator(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */
+static PyObject *__pyx_gb_5kenlm_5Model_10generator(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */
{
struct __pyx_obj_5kenlm___pyx_scope_struct__full_scores *__pyx_cur_scope = ((struct __pyx_obj_5kenlm___pyx_scope_struct__full_scores *)__pyx_generator->closure);
PyObject *__pyx_r = NULL;
@@ -2831,18 +2980,18 @@ static PyObject *__pyx_gb_5kenlm_5Model_8generator(__pyx_GeneratorObject *__pyx_
return NULL;
}
__pyx_L3_first_run:;
- if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 144; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 190; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- /* "kenlm.pyx":151
+ /* "kenlm.pyx":197
* @param eos should kenlm add an eos state
* """
* cdef list words = as_str(sentence).split() # <<<<<<<<<<<<<<
* cdef _kenlm.State state
* if bos:
*/
- __pyx_t_2 = __pyx_f_5kenlm_as_str(__pyx_cur_scope->__pyx_v_sentence); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 151; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = __pyx_f_5kenlm_as_str(__pyx_cur_scope->__pyx_v_sentence); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 197; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_split); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 151; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_split); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 197; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_3);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
__pyx_t_2 = NULL;
@@ -2856,29 +3005,29 @@ static PyObject *__pyx_gb_5kenlm_5Model_8generator(__pyx_GeneratorObject *__pyx_
}
}
if (__pyx_t_2) {
- __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 151; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 197; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
} else {
- __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 151; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 197; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
}
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- if (!(likely(PyList_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "list", Py_TYPE(__pyx_t_1)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 151; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (!(likely(PyList_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "list", Py_TYPE(__pyx_t_1)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 197; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GIVEREF(__pyx_t_1);
__pyx_cur_scope->__pyx_v_words = ((PyObject*)__pyx_t_1);
__pyx_t_1 = 0;
- /* "kenlm.pyx":153
+ /* "kenlm.pyx":199
* cdef list words = as_str(sentence).split()
* cdef _kenlm.State state
* if bos: # <<<<<<<<<<<<<<
* self.model.BeginSentenceWrite(&state)
* else:
*/
- __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_cur_scope->__pyx_v_bos); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 153; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_cur_scope->__pyx_v_bos); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 199; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
if (__pyx_t_4) {
- /* "kenlm.pyx":154
+ /* "kenlm.pyx":200
* cdef _kenlm.State state
* if bos:
* self.model.BeginSentenceWrite(&state) # <<<<<<<<<<<<<<
@@ -2890,7 +3039,7 @@ static PyObject *__pyx_gb_5kenlm_5Model_8generator(__pyx_GeneratorObject *__pyx_
}
/*else*/ {
- /* "kenlm.pyx":156
+ /* "kenlm.pyx":202
* self.model.BeginSentenceWrite(&state)
* else:
* self.model.NullContextWrite(&state) # <<<<<<<<<<<<<<
@@ -2901,7 +3050,7 @@ static PyObject *__pyx_gb_5kenlm_5Model_8generator(__pyx_GeneratorObject *__pyx_
}
__pyx_L4:;
- /* "kenlm.pyx":159
+ /* "kenlm.pyx":205
* cdef _kenlm.State out_state
* cdef _kenlm.FullScoreReturn ret
* cdef float total = 0 # <<<<<<<<<<<<<<
@@ -2910,7 +3059,7 @@ static PyObject *__pyx_gb_5kenlm_5Model_8generator(__pyx_GeneratorObject *__pyx_
*/
__pyx_cur_scope->__pyx_v_total = 0.0;
- /* "kenlm.pyx":161
+ /* "kenlm.pyx":207
* cdef float total = 0
* cdef _kenlm.WordIndex wid
* for word in words: # <<<<<<<<<<<<<<
@@ -2919,32 +3068,32 @@ static PyObject *__pyx_gb_5kenlm_5Model_8generator(__pyx_GeneratorObject *__pyx_
*/
if (unlikely(__pyx_cur_scope->__pyx_v_words == Py_None)) {
PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 161; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 207; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
}
__pyx_t_1 = __pyx_cur_scope->__pyx_v_words; __Pyx_INCREF(__pyx_t_1); __pyx_t_5 = 0;
for (;;) {
if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_1)) break;
#if CYTHON_COMPILING_IN_CPYTHON
- __pyx_t_3 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_5); __Pyx_INCREF(__pyx_t_3); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 161; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_5); __Pyx_INCREF(__pyx_t_3); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 207; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
#else
- __pyx_t_3 = PySequence_ITEM(__pyx_t_1, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 161; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = PySequence_ITEM(__pyx_t_1, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 207; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
#endif
__Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_word);
__Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_word, __pyx_t_3);
__Pyx_GIVEREF(__pyx_t_3);
__pyx_t_3 = 0;
- /* "kenlm.pyx":162
+ /* "kenlm.pyx":208
* cdef _kenlm.WordIndex wid
* for word in words:
* wid = self.vocab.Index(word) # <<<<<<<<<<<<<<
* ret = self.model.BaseFullScore(&state, wid, &out_state)
* yield (ret.prob, ret.ngram_length, wid == 0)
*/
- __pyx_t_6 = __Pyx_PyObject_AsString(__pyx_cur_scope->__pyx_v_word); if (unlikely((!__pyx_t_6) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 162; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_6 = __Pyx_PyObject_AsString(__pyx_cur_scope->__pyx_v_word); if (unlikely((!__pyx_t_6) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 208; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__pyx_cur_scope->__pyx_v_wid = __pyx_cur_scope->__pyx_v_self->vocab->Index(__pyx_t_6);
- /* "kenlm.pyx":163
+ /* "kenlm.pyx":209
* for word in words:
* wid = self.vocab.Index(word)
* ret = self.model.BaseFullScore(&state, wid, &out_state) # <<<<<<<<<<<<<<
@@ -2953,20 +3102,20 @@ static PyObject *__pyx_gb_5kenlm_5Model_8generator(__pyx_GeneratorObject *__pyx_
*/
__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_wid, (&__pyx_cur_scope->__pyx_v_out_state));
- /* "kenlm.pyx":164
+ /* "kenlm.pyx":210
* wid = self.vocab.Index(word)
* ret = self.model.BaseFullScore(&state, wid, &out_state)
* yield (ret.prob, ret.ngram_length, wid == 0) # <<<<<<<<<<<<<<
* state = out_state
* if eos:
*/
- __pyx_t_3 = PyFloat_FromDouble(__pyx_cur_scope->__pyx_v_ret.prob); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 164; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = PyFloat_FromDouble(__pyx_cur_scope->__pyx_v_ret.prob); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 210; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_3);
- __pyx_t_2 = __Pyx_PyInt_From_unsigned_char(__pyx_cur_scope->__pyx_v_ret.ngram_length); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 164; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = __Pyx_PyInt_From_unsigned_char(__pyx_cur_scope->__pyx_v_ret.ngram_length); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 210; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __pyx_t_7 = __Pyx_PyBool_FromLong((__pyx_cur_scope->__pyx_v_wid == 0)); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 164; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_7 = __Pyx_PyBool_FromLong((__pyx_cur_scope->__pyx_v_wid == 0)); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 210; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_7);
- __pyx_t_8 = PyTuple_New(3); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 164; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_8 = PyTuple_New(3); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 210; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_8);
PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_3);
__Pyx_GIVEREF(__pyx_t_3);
@@ -2992,9 +3141,9 @@ static PyObject *__pyx_gb_5kenlm_5Model_8generator(__pyx_GeneratorObject *__pyx_
__pyx_cur_scope->__pyx_t_0 = 0;
__Pyx_XGOTREF(__pyx_t_1);
__pyx_t_5 = __pyx_cur_scope->__pyx_t_1;
- if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 164; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 210; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- /* "kenlm.pyx":165
+ /* "kenlm.pyx":211
* ret = self.model.BaseFullScore(&state, wid, &out_state)
* yield (ret.prob, ret.ngram_length, wid == 0)
* state = out_state # <<<<<<<<<<<<<<
@@ -3003,7 +3152,7 @@ static PyObject *__pyx_gb_5kenlm_5Model_8generator(__pyx_GeneratorObject *__pyx_
*/
__pyx_cur_scope->__pyx_v_state = __pyx_cur_scope->__pyx_v_out_state;
- /* "kenlm.pyx":161
+ /* "kenlm.pyx":207
* cdef float total = 0
* cdef _kenlm.WordIndex wid
* for word in words: # <<<<<<<<<<<<<<
@@ -3013,17 +3162,17 @@ static PyObject *__pyx_gb_5kenlm_5Model_8generator(__pyx_GeneratorObject *__pyx_
}
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
- /* "kenlm.pyx":166
+ /* "kenlm.pyx":212
* yield (ret.prob, ret.ngram_length, wid == 0)
* state = out_state
* if eos: # <<<<<<<<<<<<<<
* ret = self.model.BaseFullScore(&state,
* self.vocab.EndSentence(), &out_state)
*/
- __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_cur_scope->__pyx_v_eos); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 166; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_cur_scope->__pyx_v_eos); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 212; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
if (__pyx_t_4) {
- /* "kenlm.pyx":167
+ /* "kenlm.pyx":213
* state = out_state
* if eos:
* ret = self.model.BaseFullScore(&state, # <<<<<<<<<<<<<<
@@ -3032,18 +3181,18 @@ static PyObject *__pyx_gb_5kenlm_5Model_8generator(__pyx_GeneratorObject *__pyx_
*/
__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":169
+ /* "kenlm.pyx":215
* ret = self.model.BaseFullScore(&state,
* self.vocab.EndSentence(), &out_state)
* yield (ret.prob, ret.ngram_length, False) # <<<<<<<<<<<<<<
*
*
*/
- __pyx_t_1 = PyFloat_FromDouble(__pyx_cur_scope->__pyx_v_ret.prob); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 169; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_1 = PyFloat_FromDouble(__pyx_cur_scope->__pyx_v_ret.prob); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 215; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
- __pyx_t_8 = __Pyx_PyInt_From_unsigned_char(__pyx_cur_scope->__pyx_v_ret.ngram_length); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 169; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_8 = __Pyx_PyInt_From_unsigned_char(__pyx_cur_scope->__pyx_v_ret.ngram_length); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 215; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_8);
- __pyx_t_7 = PyTuple_New(3); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 169; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_7 = PyTuple_New(3); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 215; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_7);
PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_1);
__Pyx_GIVEREF(__pyx_t_1);
@@ -3062,13 +3211,13 @@ static PyObject *__pyx_gb_5kenlm_5Model_8generator(__pyx_GeneratorObject *__pyx_
__pyx_generator->resume_label = 2;
return __pyx_r;
__pyx_L9_resume_from_yield:;
- if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 169; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 215; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
goto __pyx_L8;
}
__pyx_L8:;
- /* "kenlm.pyx":144
- * return total
+ /* "kenlm.pyx":190
+ * return 10.0**(-self.score(sentence) / words)
*
* def full_scores(self, sentence, bos = True, eos = True): # <<<<<<<<<<<<<<
* """
@@ -3093,7 +3242,7 @@ static PyObject *__pyx_gb_5kenlm_5Model_8generator(__pyx_GeneratorObject *__pyx_
return NULL;
}
-/* "kenlm.pyx":172
+/* "kenlm.pyx":218
*
*
* def BeginSentenceWrite(self, State state): # <<<<<<<<<<<<<<
@@ -3102,17 +3251,17 @@ static PyObject *__pyx_gb_5kenlm_5Model_8generator(__pyx_GeneratorObject *__pyx_
*/
/* Python wrapper */
-static PyObject *__pyx_pw_5kenlm_5Model_10BeginSentenceWrite(PyObject *__pyx_v_self, PyObject *__pyx_v_state); /*proto*/
-static char __pyx_doc_5kenlm_5Model_9BeginSentenceWrite[] = "Change the given state to a BOS state.";
-static PyObject *__pyx_pw_5kenlm_5Model_10BeginSentenceWrite(PyObject *__pyx_v_self, PyObject *__pyx_v_state) {
+static PyObject *__pyx_pw_5kenlm_5Model_12BeginSentenceWrite(PyObject *__pyx_v_self, PyObject *__pyx_v_state); /*proto*/
+static char __pyx_doc_5kenlm_5Model_11BeginSentenceWrite[] = "Change the given state to a BOS state.";
+static PyObject *__pyx_pw_5kenlm_5Model_12BeginSentenceWrite(PyObject *__pyx_v_self, PyObject *__pyx_v_state) {
CYTHON_UNUSED int __pyx_lineno = 0;
CYTHON_UNUSED const char *__pyx_filename = NULL;
CYTHON_UNUSED int __pyx_clineno = 0;
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("BeginSentenceWrite (wrapper)", 0);
- if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_state), __pyx_ptype_5kenlm_State, 1, "state", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 172; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __pyx_r = __pyx_pf_5kenlm_5Model_9BeginSentenceWrite(((struct __pyx_obj_5kenlm_Model *)__pyx_v_self), ((struct __pyx_obj_5kenlm_State *)__pyx_v_state));
+ if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_state), __pyx_ptype_5kenlm_State, 1, "state", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 218; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_r = __pyx_pf_5kenlm_5Model_11BeginSentenceWrite(((struct __pyx_obj_5kenlm_Model *)__pyx_v_self), ((struct __pyx_obj_5kenlm_State *)__pyx_v_state));
/* function exit code */
goto __pyx_L0;
@@ -3123,12 +3272,12 @@ static PyObject *__pyx_pw_5kenlm_5Model_10BeginSentenceWrite(PyObject *__pyx_v_s
return __pyx_r;
}
-static PyObject *__pyx_pf_5kenlm_5Model_9BeginSentenceWrite(struct __pyx_obj_5kenlm_Model *__pyx_v_self, struct __pyx_obj_5kenlm_State *__pyx_v_state) {
+static PyObject *__pyx_pf_5kenlm_5Model_11BeginSentenceWrite(struct __pyx_obj_5kenlm_Model *__pyx_v_self, struct __pyx_obj_5kenlm_State *__pyx_v_state) {
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("BeginSentenceWrite", 0);
- /* "kenlm.pyx":174
+ /* "kenlm.pyx":220
* def BeginSentenceWrite(self, State state):
* """Change the given state to a BOS state."""
* self.model.BeginSentenceWrite(&state._c_state) # <<<<<<<<<<<<<<
@@ -3137,7 +3286,7 @@ static PyObject *__pyx_pf_5kenlm_5Model_9BeginSentenceWrite(struct __pyx_obj_5ke
*/
__pyx_v_self->model->BeginSentenceWrite((&__pyx_v_state->_c_state));
- /* "kenlm.pyx":172
+ /* "kenlm.pyx":218
*
*
* def BeginSentenceWrite(self, State state): # <<<<<<<<<<<<<<
@@ -3152,7 +3301,7 @@ static PyObject *__pyx_pf_5kenlm_5Model_9BeginSentenceWrite(struct __pyx_obj_5ke
return __pyx_r;
}
-/* "kenlm.pyx":176
+/* "kenlm.pyx":222
* self.model.BeginSentenceWrite(&state._c_state)
*
* def NullContextWrite(self, State state): # <<<<<<<<<<<<<<
@@ -3161,17 +3310,17 @@ static PyObject *__pyx_pf_5kenlm_5Model_9BeginSentenceWrite(struct __pyx_obj_5ke
*/
/* Python wrapper */
-static PyObject *__pyx_pw_5kenlm_5Model_12NullContextWrite(PyObject *__pyx_v_self, PyObject *__pyx_v_state); /*proto*/
-static char __pyx_doc_5kenlm_5Model_11NullContextWrite[] = "Change the given state to a NULL state.";
-static PyObject *__pyx_pw_5kenlm_5Model_12NullContextWrite(PyObject *__pyx_v_self, PyObject *__pyx_v_state) {
+static PyObject *__pyx_pw_5kenlm_5Model_14NullContextWrite(PyObject *__pyx_v_self, PyObject *__pyx_v_state); /*proto*/
+static char __pyx_doc_5kenlm_5Model_13NullContextWrite[] = "Change the given state to a NULL state.";
+static PyObject *__pyx_pw_5kenlm_5Model_14NullContextWrite(PyObject *__pyx_v_self, PyObject *__pyx_v_state) {
CYTHON_UNUSED int __pyx_lineno = 0;
CYTHON_UNUSED const char *__pyx_filename = NULL;
CYTHON_UNUSED int __pyx_clineno = 0;
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("NullContextWrite (wrapper)", 0);
- if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_state), __pyx_ptype_5kenlm_State, 1, "state", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 176; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __pyx_r = __pyx_pf_5kenlm_5Model_11NullContextWrite(((struct __pyx_obj_5kenlm_Model *)__pyx_v_self), ((struct __pyx_obj_5kenlm_State *)__pyx_v_state));
+ if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_state), __pyx_ptype_5kenlm_State, 1, "state", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 222; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_r = __pyx_pf_5kenlm_5Model_13NullContextWrite(((struct __pyx_obj_5kenlm_Model *)__pyx_v_self), ((struct __pyx_obj_5kenlm_State *)__pyx_v_state));
/* function exit code */
goto __pyx_L0;
@@ -3182,12 +3331,12 @@ static PyObject *__pyx_pw_5kenlm_5Model_12NullContextWrite(PyObject *__pyx_v_sel
return __pyx_r;
}
-static PyObject *__pyx_pf_5kenlm_5Model_11NullContextWrite(struct __pyx_obj_5kenlm_Model *__pyx_v_self, struct __pyx_obj_5kenlm_State *__pyx_v_state) {
+static PyObject *__pyx_pf_5kenlm_5Model_13NullContextWrite(struct __pyx_obj_5kenlm_Model *__pyx_v_self, struct __pyx_obj_5kenlm_State *__pyx_v_state) {
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("NullContextWrite", 0);
- /* "kenlm.pyx":178
+ /* "kenlm.pyx":224
* def NullContextWrite(self, State state):
* """Change the given state to a NULL state."""
* self.model.NullContextWrite(&state._c_state) # <<<<<<<<<<<<<<
@@ -3196,7 +3345,7 @@ static PyObject *__pyx_pf_5kenlm_5Model_11NullContextWrite(struct __pyx_obj_5ken
*/
__pyx_v_self->model->NullContextWrite((&__pyx_v_state->_c_state));
- /* "kenlm.pyx":176
+ /* "kenlm.pyx":222
* self.model.BeginSentenceWrite(&state._c_state)
*
* def NullContextWrite(self, State state): # <<<<<<<<<<<<<<
@@ -3211,7 +3360,7 @@ static PyObject *__pyx_pf_5kenlm_5Model_11NullContextWrite(struct __pyx_obj_5ken
return __pyx_r;
}
-/* "kenlm.pyx":180
+/* "kenlm.pyx":226
* self.model.NullContextWrite(&state._c_state)
*
* def BaseScore(self, State in_state, str word, State out_state): # <<<<<<<<<<<<<<
@@ -3220,9 +3369,9 @@ static PyObject *__pyx_pf_5kenlm_5Model_11NullContextWrite(struct __pyx_obj_5ken
*/
/* Python wrapper */
-static PyObject *__pyx_pw_5kenlm_5Model_14BaseScore(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
-static char __pyx_doc_5kenlm_5Model_13BaseScore[] = "\n Return p(word|in_state) and update the output state.\n Wrapper around model.BaseScore(in_state, Index(word), out_state)\n\n :param word: the suffix\n :param state: the context (defaults to NullContext)\n :returns: p(word|state)\n ";
-static PyObject *__pyx_pw_5kenlm_5Model_14BaseScore(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+static PyObject *__pyx_pw_5kenlm_5Model_16BaseScore(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static char __pyx_doc_5kenlm_5Model_15BaseScore[] = "\n Return p(word|in_state) and update the output state.\n Wrapper around model.BaseScore(in_state, Index(word), out_state)\n\n :param word: the suffix\n :param state: the context (defaults to NullContext)\n :returns: p(word|state)\n ";
+static PyObject *__pyx_pw_5kenlm_5Model_16BaseScore(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
struct __pyx_obj_5kenlm_State *__pyx_v_in_state = 0;
PyObject *__pyx_v_word = 0;
struct __pyx_obj_5kenlm_State *__pyx_v_out_state = 0;
@@ -3253,16 +3402,16 @@ static PyObject *__pyx_pw_5kenlm_5Model_14BaseScore(PyObject *__pyx_v_self, PyOb
case 1:
if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_word)) != 0)) kw_args--;
else {
- __Pyx_RaiseArgtupleInvalid("BaseScore", 1, 3, 3, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 180; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ __Pyx_RaiseArgtupleInvalid("BaseScore", 1, 3, 3, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 226; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
}
case 2:
if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_out_state)) != 0)) kw_args--;
else {
- __Pyx_RaiseArgtupleInvalid("BaseScore", 1, 3, 3, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 180; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ __Pyx_RaiseArgtupleInvalid("BaseScore", 1, 3, 3, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 226; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
}
}
if (unlikely(kw_args > 0)) {
- if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "BaseScore") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 180; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "BaseScore") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 226; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
}
} else if (PyTuple_GET_SIZE(__pyx_args) != 3) {
goto __pyx_L5_argtuple_error;
@@ -3277,16 +3426,16 @@ static PyObject *__pyx_pw_5kenlm_5Model_14BaseScore(PyObject *__pyx_v_self, PyOb
}
goto __pyx_L4_argument_unpacking_done;
__pyx_L5_argtuple_error:;
- __Pyx_RaiseArgtupleInvalid("BaseScore", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 180; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ __Pyx_RaiseArgtupleInvalid("BaseScore", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 226; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
__pyx_L3_error:;
__Pyx_AddTraceback("kenlm.Model.BaseScore", __pyx_clineno, __pyx_lineno, __pyx_filename);
__Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
- if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_in_state), __pyx_ptype_5kenlm_State, 1, "in_state", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 180; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_word), (&PyString_Type), 1, "word", 1))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 180; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_out_state), __pyx_ptype_5kenlm_State, 1, "out_state", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 180; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __pyx_r = __pyx_pf_5kenlm_5Model_13BaseScore(((struct __pyx_obj_5kenlm_Model *)__pyx_v_self), __pyx_v_in_state, __pyx_v_word, __pyx_v_out_state);
+ if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_in_state), __pyx_ptype_5kenlm_State, 1, "in_state", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 226; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_word), (&PyString_Type), 1, "word", 1))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 226; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_out_state), __pyx_ptype_5kenlm_State, 1, "out_state", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 226; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_r = __pyx_pf_5kenlm_5Model_15BaseScore(((struct __pyx_obj_5kenlm_Model *)__pyx_v_self), __pyx_v_in_state, __pyx_v_word, __pyx_v_out_state);
/* function exit code */
goto __pyx_L0;
@@ -3297,7 +3446,7 @@ static PyObject *__pyx_pw_5kenlm_5Model_14BaseScore(PyObject *__pyx_v_self, PyOb
return __pyx_r;
}
-static PyObject *__pyx_pf_5kenlm_5Model_13BaseScore(struct __pyx_obj_5kenlm_Model *__pyx_v_self, struct __pyx_obj_5kenlm_State *__pyx_v_in_state, PyObject *__pyx_v_word, struct __pyx_obj_5kenlm_State *__pyx_v_out_state) {
+static PyObject *__pyx_pf_5kenlm_5Model_15BaseScore(struct __pyx_obj_5kenlm_Model *__pyx_v_self, struct __pyx_obj_5kenlm_State *__pyx_v_in_state, PyObject *__pyx_v_word, struct __pyx_obj_5kenlm_State *__pyx_v_out_state) {
float __pyx_v_total;
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
@@ -3308,20 +3457,20 @@ static PyObject *__pyx_pf_5kenlm_5Model_13BaseScore(struct __pyx_obj_5kenlm_Mode
int __pyx_clineno = 0;
__Pyx_RefNannySetupContext("BaseScore", 0);
- /* "kenlm.pyx":189
+ /* "kenlm.pyx":235
* :returns: p(word|state)
* """
* cdef float total = self.model.BaseScore(&in_state._c_state, self.vocab.Index(as_str(word)), &out_state._c_state) # <<<<<<<<<<<<<<
* return total
*
*/
- __pyx_t_1 = __pyx_f_5kenlm_as_str(__pyx_v_word); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 189; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_1 = __pyx_f_5kenlm_as_str(__pyx_v_word); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 235; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
- __pyx_t_2 = __Pyx_PyObject_AsString(__pyx_t_1); if (unlikely((!__pyx_t_2) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 189; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = __Pyx_PyObject_AsString(__pyx_t_1); if (unlikely((!__pyx_t_2) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 235; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__pyx_v_total = __pyx_v_self->model->BaseScore((&__pyx_v_in_state->_c_state), __pyx_v_self->vocab->Index(__pyx_t_2), (&__pyx_v_out_state->_c_state));
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
- /* "kenlm.pyx":190
+ /* "kenlm.pyx":236
* """
* cdef float total = self.model.BaseScore(&in_state._c_state, self.vocab.Index(as_str(word)), &out_state._c_state)
* return total # <<<<<<<<<<<<<<
@@ -3329,13 +3478,13 @@ static PyObject *__pyx_pf_5kenlm_5Model_13BaseScore(struct __pyx_obj_5kenlm_Mode
* def BaseFullScore(self, State in_state, str word, State out_state):
*/
__Pyx_XDECREF(__pyx_r);
- __pyx_t_1 = PyFloat_FromDouble(__pyx_v_total); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 190; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_1 = PyFloat_FromDouble(__pyx_v_total); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 236; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
__pyx_r = __pyx_t_1;
__pyx_t_1 = 0;
goto __pyx_L0;
- /* "kenlm.pyx":180
+ /* "kenlm.pyx":226
* self.model.NullContextWrite(&state._c_state)
*
* def BaseScore(self, State in_state, str word, State out_state): # <<<<<<<<<<<<<<
@@ -3354,7 +3503,7 @@ static PyObject *__pyx_pf_5kenlm_5Model_13BaseScore(struct __pyx_obj_5kenlm_Mode
return __pyx_r;
}
-/* "kenlm.pyx":192
+/* "kenlm.pyx":238
* return total
*
* def BaseFullScore(self, State in_state, str word, State out_state): # <<<<<<<<<<<<<<
@@ -3363,9 +3512,9 @@ static PyObject *__pyx_pf_5kenlm_5Model_13BaseScore(struct __pyx_obj_5kenlm_Mode
*/
/* Python wrapper */
-static PyObject *__pyx_pw_5kenlm_5Model_16BaseFullScore(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
-static char __pyx_doc_5kenlm_5Model_15BaseFullScore[] = "\n Wrapper around model.BaseScore(in_state, Index(word), out_state)\n\n :param word: the suffix\n :param state: the context (defaults to NullContext)\n :returns: FullScoreReturn(word|state)\n ";
-static PyObject *__pyx_pw_5kenlm_5Model_16BaseFullScore(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+static PyObject *__pyx_pw_5kenlm_5Model_18BaseFullScore(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static char __pyx_doc_5kenlm_5Model_17BaseFullScore[] = "\n Wrapper around model.BaseScore(in_state, Index(word), out_state)\n\n :param word: the suffix\n :param state: the context (defaults to NullContext)\n :returns: FullScoreReturn(word|state)\n ";
+static PyObject *__pyx_pw_5kenlm_5Model_18BaseFullScore(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
struct __pyx_obj_5kenlm_State *__pyx_v_in_state = 0;
PyObject *__pyx_v_word = 0;
struct __pyx_obj_5kenlm_State *__pyx_v_out_state = 0;
@@ -3396,16 +3545,16 @@ static PyObject *__pyx_pw_5kenlm_5Model_16BaseFullScore(PyObject *__pyx_v_self,
case 1:
if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_word)) != 0)) kw_args--;
else {
- __Pyx_RaiseArgtupleInvalid("BaseFullScore", 1, 3, 3, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 192; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ __Pyx_RaiseArgtupleInvalid("BaseFullScore", 1, 3, 3, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 238; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
}
case 2:
if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_out_state)) != 0)) kw_args--;
else {
- __Pyx_RaiseArgtupleInvalid("BaseFullScore", 1, 3, 3, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 192; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ __Pyx_RaiseArgtupleInvalid("BaseFullScore", 1, 3, 3, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 238; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
}
}
if (unlikely(kw_args > 0)) {
- if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "BaseFullScore") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 192; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "BaseFullScore") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 238; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
}
} else if (PyTuple_GET_SIZE(__pyx_args) != 3) {
goto __pyx_L5_argtuple_error;
@@ -3420,16 +3569,16 @@ static PyObject *__pyx_pw_5kenlm_5Model_16BaseFullScore(PyObject *__pyx_v_self,
}
goto __pyx_L4_argument_unpacking_done;
__pyx_L5_argtuple_error:;
- __Pyx_RaiseArgtupleInvalid("BaseFullScore", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 192; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ __Pyx_RaiseArgtupleInvalid("BaseFullScore", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 238; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
__pyx_L3_error:;
__Pyx_AddTraceback("kenlm.Model.BaseFullScore", __pyx_clineno, __pyx_lineno, __pyx_filename);
__Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
- if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_in_state), __pyx_ptype_5kenlm_State, 1, "in_state", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 192; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_word), (&PyString_Type), 1, "word", 1))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 192; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_out_state), __pyx_ptype_5kenlm_State, 1, "out_state", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 192; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __pyx_r = __pyx_pf_5kenlm_5Model_15BaseFullScore(((struct __pyx_obj_5kenlm_Model *)__pyx_v_self), __pyx_v_in_state, __pyx_v_word, __pyx_v_out_state);
+ if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_in_state), __pyx_ptype_5kenlm_State, 1, "in_state", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 238; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_word), (&PyString_Type), 1, "word", 1))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 238; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_out_state), __pyx_ptype_5kenlm_State, 1, "out_state", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 238; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_r = __pyx_pf_5kenlm_5Model_17BaseFullScore(((struct __pyx_obj_5kenlm_Model *)__pyx_v_self), __pyx_v_in_state, __pyx_v_word, __pyx_v_out_state);
/* function exit code */
goto __pyx_L0;
@@ -3440,7 +3589,7 @@ static PyObject *__pyx_pw_5kenlm_5Model_16BaseFullScore(PyObject *__pyx_v_self,
return __pyx_r;
}
-static PyObject *__pyx_pf_5kenlm_5Model_15BaseFullScore(struct __pyx_obj_5kenlm_Model *__pyx_v_self, struct __pyx_obj_5kenlm_State *__pyx_v_in_state, PyObject *__pyx_v_word, struct __pyx_obj_5kenlm_State *__pyx_v_out_state) {
+static PyObject *__pyx_pf_5kenlm_5Model_17BaseFullScore(struct __pyx_obj_5kenlm_Model *__pyx_v_self, struct __pyx_obj_5kenlm_State *__pyx_v_in_state, PyObject *__pyx_v_word, struct __pyx_obj_5kenlm_State *__pyx_v_out_state) {
lm::WordIndex __pyx_v_wid;
struct lm::FullScoreReturn __pyx_v_ret;
PyObject *__pyx_r = NULL;
@@ -3455,20 +3604,20 @@ static PyObject *__pyx_pf_5kenlm_5Model_15BaseFullScore(struct __pyx_obj_5kenlm_
int __pyx_clineno = 0;
__Pyx_RefNannySetupContext("BaseFullScore", 0);
- /* "kenlm.pyx":200
+ /* "kenlm.pyx":246
* :returns: FullScoreReturn(word|state)
* """
* cdef _kenlm.WordIndex wid = self.vocab.Index(as_str(word)) # <<<<<<<<<<<<<<
* cdef _kenlm.FullScoreReturn ret = self.model.BaseFullScore(&in_state._c_state, wid, &out_state._c_state)
* return FullScoreReturn(ret.prob, ret.ngram_length, wid == 0)
*/
- __pyx_t_1 = __pyx_f_5kenlm_as_str(__pyx_v_word); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 200; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_1 = __pyx_f_5kenlm_as_str(__pyx_v_word); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 246; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
- __pyx_t_2 = __Pyx_PyObject_AsString(__pyx_t_1); if (unlikely((!__pyx_t_2) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 200; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = __Pyx_PyObject_AsString(__pyx_t_1); if (unlikely((!__pyx_t_2) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 246; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__pyx_v_wid = __pyx_v_self->vocab->Index(__pyx_t_2);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
- /* "kenlm.pyx":201
+ /* "kenlm.pyx":247
* """
* cdef _kenlm.WordIndex wid = self.vocab.Index(as_str(word))
* cdef _kenlm.FullScoreReturn ret = self.model.BaseFullScore(&in_state._c_state, wid, &out_state._c_state) # <<<<<<<<<<<<<<
@@ -3477,7 +3626,7 @@ static PyObject *__pyx_pf_5kenlm_5Model_15BaseFullScore(struct __pyx_obj_5kenlm_
*/
__pyx_v_ret = __pyx_v_self->model->BaseFullScore((&__pyx_v_in_state->_c_state), __pyx_v_wid, (&__pyx_v_out_state->_c_state));
- /* "kenlm.pyx":202
+ /* "kenlm.pyx":248
* cdef _kenlm.WordIndex wid = self.vocab.Index(as_str(word))
* cdef _kenlm.FullScoreReturn ret = self.model.BaseFullScore(&in_state._c_state, wid, &out_state._c_state)
* return FullScoreReturn(ret.prob, ret.ngram_length, wid == 0) # <<<<<<<<<<<<<<
@@ -3485,13 +3634,13 @@ static PyObject *__pyx_pf_5kenlm_5Model_15BaseFullScore(struct __pyx_obj_5kenlm_
* def __contains__(self, word):
*/
__Pyx_XDECREF(__pyx_r);
- __pyx_t_1 = PyFloat_FromDouble(__pyx_v_ret.prob); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 202; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_1 = PyFloat_FromDouble(__pyx_v_ret.prob); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 248; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
- __pyx_t_3 = __Pyx_PyInt_From_unsigned_char(__pyx_v_ret.ngram_length); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 202; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = __Pyx_PyInt_From_unsigned_char(__pyx_v_ret.ngram_length); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 248; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_3);
- __pyx_t_4 = __Pyx_PyBool_FromLong((__pyx_v_wid == 0)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 202; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = __Pyx_PyBool_FromLong((__pyx_v_wid == 0)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 248; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_4);
- __pyx_t_5 = PyTuple_New(3); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 202; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_5 = PyTuple_New(3); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 248; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_5);
PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_1);
__Pyx_GIVEREF(__pyx_t_1);
@@ -3502,14 +3651,14 @@ static PyObject *__pyx_pf_5kenlm_5Model_15BaseFullScore(struct __pyx_obj_5kenlm_
__pyx_t_1 = 0;
__pyx_t_3 = 0;
__pyx_t_4 = 0;
- __pyx_t_4 = __Pyx_PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5kenlm_FullScoreReturn)), __pyx_t_5, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 202; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = __Pyx_PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5kenlm_FullScoreReturn)), __pyx_t_5, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 248; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_4);
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
__pyx_r = __pyx_t_4;
__pyx_t_4 = 0;
goto __pyx_L0;
- /* "kenlm.pyx":192
+ /* "kenlm.pyx":238
* return total
*
* def BaseFullScore(self, State in_state, str word, State out_state): # <<<<<<<<<<<<<<
@@ -3531,7 +3680,7 @@ static PyObject *__pyx_pf_5kenlm_5Model_15BaseFullScore(struct __pyx_obj_5kenlm_
return __pyx_r;
}
-/* "kenlm.pyx":204
+/* "kenlm.pyx":250
* return FullScoreReturn(ret.prob, ret.ngram_length, wid == 0)
*
* def __contains__(self, word): # <<<<<<<<<<<<<<
@@ -3540,19 +3689,19 @@ static PyObject *__pyx_pf_5kenlm_5Model_15BaseFullScore(struct __pyx_obj_5kenlm_
*/
/* Python wrapper */
-static int __pyx_pw_5kenlm_5Model_18__contains__(PyObject *__pyx_v_self, PyObject *__pyx_v_word); /*proto*/
-static int __pyx_pw_5kenlm_5Model_18__contains__(PyObject *__pyx_v_self, PyObject *__pyx_v_word) {
+static int __pyx_pw_5kenlm_5Model_20__contains__(PyObject *__pyx_v_self, PyObject *__pyx_v_word); /*proto*/
+static int __pyx_pw_5kenlm_5Model_20__contains__(PyObject *__pyx_v_self, PyObject *__pyx_v_word) {
int __pyx_r;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("__contains__ (wrapper)", 0);
- __pyx_r = __pyx_pf_5kenlm_5Model_17__contains__(((struct __pyx_obj_5kenlm_Model *)__pyx_v_self), ((PyObject *)__pyx_v_word));
+ __pyx_r = __pyx_pf_5kenlm_5Model_19__contains__(((struct __pyx_obj_5kenlm_Model *)__pyx_v_self), ((PyObject *)__pyx_v_word));
/* function exit code */
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
-static int __pyx_pf_5kenlm_5Model_17__contains__(struct __pyx_obj_5kenlm_Model *__pyx_v_self, PyObject *__pyx_v_word) {
+static int __pyx_pf_5kenlm_5Model_19__contains__(struct __pyx_obj_5kenlm_Model *__pyx_v_self, PyObject *__pyx_v_word) {
PyObject *__pyx_v_w = 0;
int __pyx_r;
__Pyx_RefNannyDeclarations
@@ -3563,30 +3712,30 @@ static int __pyx_pf_5kenlm_5Model_17__contains__(struct __pyx_obj_5kenlm_Model *
int __pyx_clineno = 0;
__Pyx_RefNannySetupContext("__contains__", 0);
- /* "kenlm.pyx":205
+ /* "kenlm.pyx":251
*
* def __contains__(self, word):
* cdef bytes w = as_str(word) # <<<<<<<<<<<<<<
* return (self.vocab.Index(w) != 0)
*
*/
- __pyx_t_1 = __pyx_f_5kenlm_as_str(__pyx_v_word); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 205; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_1 = __pyx_f_5kenlm_as_str(__pyx_v_word); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 251; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
__pyx_v_w = ((PyObject*)__pyx_t_1);
__pyx_t_1 = 0;
- /* "kenlm.pyx":206
+ /* "kenlm.pyx":252
* def __contains__(self, word):
* cdef bytes w = as_str(word)
* return (self.vocab.Index(w) != 0) # <<<<<<<<<<<<<<
*
* def __repr__(self):
*/
- __pyx_t_2 = __Pyx_PyObject_AsString(__pyx_v_w); if (unlikely((!__pyx_t_2) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 206; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = __Pyx_PyObject_AsString(__pyx_v_w); if (unlikely((!__pyx_t_2) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 252; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__pyx_r = (__pyx_v_self->vocab->Index(__pyx_t_2) != 0);
goto __pyx_L0;
- /* "kenlm.pyx":204
+ /* "kenlm.pyx":250
* return FullScoreReturn(ret.prob, ret.ngram_length, wid == 0)
*
* def __contains__(self, word): # <<<<<<<<<<<<<<
@@ -3605,7 +3754,7 @@ static int __pyx_pf_5kenlm_5Model_17__contains__(struct __pyx_obj_5kenlm_Model *
return __pyx_r;
}
-/* "kenlm.pyx":208
+/* "kenlm.pyx":254
* return (self.vocab.Index(w) != 0)
*
* def __repr__(self): # <<<<<<<<<<<<<<
@@ -3614,19 +3763,19 @@ static int __pyx_pf_5kenlm_5Model_17__contains__(struct __pyx_obj_5kenlm_Model *
*/
/* Python wrapper */
-static PyObject *__pyx_pw_5kenlm_5Model_20__repr__(PyObject *__pyx_v_self); /*proto*/
-static PyObject *__pyx_pw_5kenlm_5Model_20__repr__(PyObject *__pyx_v_self) {
+static PyObject *__pyx_pw_5kenlm_5Model_22__repr__(PyObject *__pyx_v_self); /*proto*/
+static PyObject *__pyx_pw_5kenlm_5Model_22__repr__(PyObject *__pyx_v_self) {
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("__repr__ (wrapper)", 0);
- __pyx_r = __pyx_pf_5kenlm_5Model_19__repr__(((struct __pyx_obj_5kenlm_Model *)__pyx_v_self));
+ __pyx_r = __pyx_pf_5kenlm_5Model_21__repr__(((struct __pyx_obj_5kenlm_Model *)__pyx_v_self));
/* function exit code */
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
-static PyObject *__pyx_pf_5kenlm_5Model_19__repr__(struct __pyx_obj_5kenlm_Model *__pyx_v_self) {
+static PyObject *__pyx_pf_5kenlm_5Model_21__repr__(struct __pyx_obj_5kenlm_Model *__pyx_v_self) {
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
PyObject *__pyx_t_1 = NULL;
@@ -3640,7 +3789,7 @@ static PyObject *__pyx_pf_5kenlm_5Model_19__repr__(struct __pyx_obj_5kenlm_Model
int __pyx_clineno = 0;
__Pyx_RefNannySetupContext("__repr__", 0);
- /* "kenlm.pyx":209
+ /* "kenlm.pyx":255
*
* def __repr__(self):
* return '<Model from {0}>'.format(os.path.basename(self.path)) # <<<<<<<<<<<<<<
@@ -3648,14 +3797,14 @@ static PyObject *__pyx_pf_5kenlm_5Model_19__repr__(struct __pyx_obj_5kenlm_Model
* def __reduce__(self):
*/
__Pyx_XDECREF(__pyx_r);
- __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_Model_from_0, __pyx_n_s_format); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 209; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_Model_from_0, __pyx_n_s_format); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 255; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_os); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 209; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_os); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 255; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_4);
- __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_path); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 209; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_path); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 255; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_5);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_basename); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 209; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_basename); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 255; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_4);
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
__pyx_t_5 = NULL;
@@ -3669,16 +3818,16 @@ static PyObject *__pyx_pf_5kenlm_5Model_19__repr__(struct __pyx_obj_5kenlm_Model
}
}
if (!__pyx_t_5) {
- __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_v_self->path); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 209; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_v_self->path); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 255; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_3);
} else {
- __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 209; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 255; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_6);
PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_5); __Pyx_GIVEREF(__pyx_t_5); __pyx_t_5 = NULL;
__Pyx_INCREF(__pyx_v_self->path);
PyTuple_SET_ITEM(__pyx_t_6, 0+1, __pyx_v_self->path);
__Pyx_GIVEREF(__pyx_v_self->path);
- __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_6, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 209; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_6, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 255; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_3);
__Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
}
@@ -3694,17 +3843,17 @@ static PyObject *__pyx_pf_5kenlm_5Model_19__repr__(struct __pyx_obj_5kenlm_Model
}
}
if (!__pyx_t_4) {
- __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 209; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 255; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
__Pyx_GOTREF(__pyx_t_1);
} else {
- __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 209; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 255; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_6);
PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_4); __Pyx_GIVEREF(__pyx_t_4); __pyx_t_4 = NULL;
PyTuple_SET_ITEM(__pyx_t_6, 0+1, __pyx_t_3);
__Pyx_GIVEREF(__pyx_t_3);
__pyx_t_3 = 0;
- __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_6, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 209; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_6, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 255; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
}
@@ -3713,7 +3862,7 @@ static PyObject *__pyx_pf_5kenlm_5Model_19__repr__(struct __pyx_obj_5kenlm_Model
__pyx_t_1 = 0;
goto __pyx_L0;
- /* "kenlm.pyx":208
+ /* "kenlm.pyx":254
* return (self.vocab.Index(w) != 0)
*
* def __repr__(self): # <<<<<<<<<<<<<<
@@ -3737,7 +3886,7 @@ static PyObject *__pyx_pf_5kenlm_5Model_19__repr__(struct __pyx_obj_5kenlm_Model
return __pyx_r;
}
-/* "kenlm.pyx":211
+/* "kenlm.pyx":257
* return '<Model from {0}>'.format(os.path.basename(self.path))
*
* def __reduce__(self): # <<<<<<<<<<<<<<
@@ -3746,19 +3895,19 @@ static PyObject *__pyx_pf_5kenlm_5Model_19__repr__(struct __pyx_obj_5kenlm_Model
*/
/* Python wrapper */
-static PyObject *__pyx_pw_5kenlm_5Model_22__reduce__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
-static PyObject *__pyx_pw_5kenlm_5Model_22__reduce__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
+static PyObject *__pyx_pw_5kenlm_5Model_24__reduce__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
+static PyObject *__pyx_pw_5kenlm_5Model_24__reduce__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("__reduce__ (wrapper)", 0);
- __pyx_r = __pyx_pf_5kenlm_5Model_21__reduce__(((struct __pyx_obj_5kenlm_Model *)__pyx_v_self));
+ __pyx_r = __pyx_pf_5kenlm_5Model_23__reduce__(((struct __pyx_obj_5kenlm_Model *)__pyx_v_self));
/* function exit code */
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
-static PyObject *__pyx_pf_5kenlm_5Model_21__reduce__(struct __pyx_obj_5kenlm_Model *__pyx_v_self) {
+static PyObject *__pyx_pf_5kenlm_5Model_23__reduce__(struct __pyx_obj_5kenlm_Model *__pyx_v_self) {
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
PyObject *__pyx_t_1 = NULL;
@@ -3769,7 +3918,7 @@ static PyObject *__pyx_pf_5kenlm_5Model_21__reduce__(struct __pyx_obj_5kenlm_Mod
int __pyx_clineno = 0;
__Pyx_RefNannySetupContext("__reduce__", 0);
- /* "kenlm.pyx":212
+ /* "kenlm.pyx":258
*
* def __reduce__(self):
* return (_kenlm.LanguageModel, (self.path,)) # <<<<<<<<<<<<<<
@@ -3777,17 +3926,17 @@ static PyObject *__pyx_pf_5kenlm_5Model_21__reduce__(struct __pyx_obj_5kenlm_Mod
* class LanguageModel(Model):
*/
__Pyx_XDECREF(__pyx_r);
- __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_kenlm); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 212; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_kenlm); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 258; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
- __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_LanguageModel); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 212; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_LanguageModel); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 258; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
- __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 212; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 258; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
__Pyx_INCREF(__pyx_v_self->path);
PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_self->path);
__Pyx_GIVEREF(__pyx_v_self->path);
- __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 212; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 258; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_3);
PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2);
__Pyx_GIVEREF(__pyx_t_2);
@@ -3799,7 +3948,7 @@ static PyObject *__pyx_pf_5kenlm_5Model_21__reduce__(struct __pyx_obj_5kenlm_Mod
__pyx_t_3 = 0;
goto __pyx_L0;
- /* "kenlm.pyx":211
+ /* "kenlm.pyx":257
* return '<Model from {0}>'.format(os.path.basename(self.path))
*
* def __reduce__(self): # <<<<<<<<<<<<<<
@@ -4273,13 +4422,14 @@ static int __pyx_setprop_5kenlm_5Model_path(PyObject *o, PyObject *v, CYTHON_UNU
}
static PyMethodDef __pyx_methods_5kenlm_Model[] = {
- {"score", (PyCFunction)__pyx_pw_5kenlm_5Model_5score, METH_VARARGS|METH_KEYWORDS, 0},
- {"full_scores", (PyCFunction)__pyx_pw_5kenlm_5Model_7full_scores, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5kenlm_5Model_6full_scores},
- {"BeginSentenceWrite", (PyCFunction)__pyx_pw_5kenlm_5Model_10BeginSentenceWrite, METH_O, __pyx_doc_5kenlm_5Model_9BeginSentenceWrite},
- {"NullContextWrite", (PyCFunction)__pyx_pw_5kenlm_5Model_12NullContextWrite, METH_O, __pyx_doc_5kenlm_5Model_11NullContextWrite},
- {"BaseScore", (PyCFunction)__pyx_pw_5kenlm_5Model_14BaseScore, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5kenlm_5Model_13BaseScore},
- {"BaseFullScore", (PyCFunction)__pyx_pw_5kenlm_5Model_16BaseFullScore, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5kenlm_5Model_15BaseFullScore},
- {"__reduce__", (PyCFunction)__pyx_pw_5kenlm_5Model_22__reduce__, METH_NOARGS, 0},
+ {"score", (PyCFunction)__pyx_pw_5kenlm_5Model_5score, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5kenlm_5Model_4score},
+ {"perplexity", (PyCFunction)__pyx_pw_5kenlm_5Model_7perplexity, METH_O, __pyx_doc_5kenlm_5Model_6perplexity},
+ {"full_scores", (PyCFunction)__pyx_pw_5kenlm_5Model_9full_scores, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5kenlm_5Model_8full_scores},
+ {"BeginSentenceWrite", (PyCFunction)__pyx_pw_5kenlm_5Model_12BeginSentenceWrite, METH_O, __pyx_doc_5kenlm_5Model_11BeginSentenceWrite},
+ {"NullContextWrite", (PyCFunction)__pyx_pw_5kenlm_5Model_14NullContextWrite, METH_O, __pyx_doc_5kenlm_5Model_13NullContextWrite},
+ {"BaseScore", (PyCFunction)__pyx_pw_5kenlm_5Model_16BaseScore, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5kenlm_5Model_15BaseScore},
+ {"BaseFullScore", (PyCFunction)__pyx_pw_5kenlm_5Model_18BaseFullScore, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5kenlm_5Model_17BaseFullScore},
+ {"__reduce__", (PyCFunction)__pyx_pw_5kenlm_5Model_24__reduce__, METH_NOARGS, 0},
{0, 0, 0, 0}
};
@@ -4297,7 +4447,7 @@ static PySequenceMethods __pyx_tp_as_sequence_Model = {
0, /*sq_slice*/
0, /*sq_ass_item*/
0, /*sq_ass_slice*/
- __pyx_pw_5kenlm_5Model_18__contains__, /*sq_contains*/
+ __pyx_pw_5kenlm_5Model_20__contains__, /*sq_contains*/
0, /*sq_inplace_concat*/
0, /*sq_inplace_repeat*/
};
@@ -4316,7 +4466,7 @@ static PyTypeObject __pyx_type_5kenlm_Model = {
#else
0, /*reserved*/
#endif
- __pyx_pw_5kenlm_5Model_20__repr__, /*tp_repr*/
+ __pyx_pw_5kenlm_5Model_22__repr__, /*tp_repr*/
0, /*tp_as_number*/
&__pyx_tp_as_sequence_Model, /*tp_as_sequence*/
0, /*tp_as_mapping*/
@@ -4580,6 +4730,7 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = {
{&__pyx_n_s_prepare, __pyx_k_prepare, sizeof(__pyx_k_prepare), 0, 0, 1, 1},
{&__pyx_n_s_qualname, __pyx_k_qualname, sizeof(__pyx_k_qualname), 0, 0, 1, 1},
{&__pyx_n_s_replace, __pyx_k_replace, sizeof(__pyx_k_replace), 0, 0, 1, 1},
+ {&__pyx_n_s_score, __pyx_k_score, sizeof(__pyx_k_score), 0, 0, 1, 1},
{&__pyx_n_s_send, __pyx_k_send, sizeof(__pyx_k_send), 0, 0, 1, 1},
{&__pyx_n_s_sentence, __pyx_k_sentence, sizeof(__pyx_k_sentence), 0, 0, 1, 1},
{&__pyx_n_s_split, __pyx_k_split, sizeof(__pyx_k_split), 0, 0, 1, 1},
@@ -4632,6 +4783,7 @@ static int __Pyx_InitCachedConstants(void) {
static int __Pyx_InitGlobals(void) {
if (__Pyx_InitStrings(__pyx_string_tab) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
+ __pyx_float_10_0 = PyFloat_FromDouble(10.0); if (unlikely(!__pyx_float_10_0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
return 0;
__pyx_L1_error:;
return -1;
@@ -4746,7 +4898,7 @@ PyMODINIT_FUNC PyInit_kenlm(void)
#endif
if (PyObject_SetAttrString(__pyx_m, "Model", (PyObject *)&__pyx_type_5kenlm_Model) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 96; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__pyx_ptype_5kenlm_Model = &__pyx_type_5kenlm_Model;
- if (PyType_Ready(&__pyx_type_5kenlm___pyx_scope_struct__full_scores) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 144; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (PyType_Ready(&__pyx_type_5kenlm___pyx_scope_struct__full_scores) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 190; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__pyx_type_5kenlm___pyx_scope_struct__full_scores.tp_print = 0;
__pyx_ptype_5kenlm___pyx_scope_struct__full_scores = &__pyx_type_5kenlm___pyx_scope_struct__full_scores;
/*--- Type import code ---*/
@@ -4860,24 +5012,24 @@ PyMODINIT_FUNC PyInit_kenlm(void)
__Pyx_GIVEREF(__pyx_t_1);
__pyx_t_1 = 0;
- /* "kenlm.pyx":214
+ /* "kenlm.pyx":260
* return (_kenlm.LanguageModel, (self.path,))
*
* class LanguageModel(Model): # <<<<<<<<<<<<<<
* """Backwards compatability stub. Use Model."""
*/
- __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 214; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 260; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
__Pyx_INCREF(((PyObject *)((PyObject*)__pyx_ptype_5kenlm_Model)));
PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)((PyObject*)__pyx_ptype_5kenlm_Model)));
__Pyx_GIVEREF(((PyObject *)((PyObject*)__pyx_ptype_5kenlm_Model)));
- __pyx_t_2 = __Pyx_CalculateMetaclass(NULL, __pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 214; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = __Pyx_CalculateMetaclass(NULL, __pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 260; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
- __pyx_t_3 = __Pyx_Py3MetaclassPrepare(__pyx_t_2, __pyx_t_1, __pyx_n_s_LanguageModel, __pyx_n_s_LanguageModel, (PyObject *) NULL, __pyx_n_s_kenlm_2, __pyx_kp_s_Backwards_compatability_stub_Use); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 214; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = __Pyx_Py3MetaclassPrepare(__pyx_t_2, __pyx_t_1, __pyx_n_s_LanguageModel, __pyx_n_s_LanguageModel, (PyObject *) NULL, __pyx_n_s_kenlm_2, __pyx_kp_s_Backwards_compatability_stub_Use); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 260; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_3);
- __pyx_t_4 = __Pyx_Py3ClassCreate(__pyx_t_2, __pyx_n_s_LanguageModel, __pyx_t_1, __pyx_t_3, NULL, 0, 1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 214; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = __Pyx_Py3ClassCreate(__pyx_t_2, __pyx_n_s_LanguageModel, __pyx_t_1, __pyx_t_3, NULL, 0, 1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 260; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_4);
- if (PyDict_SetItem(__pyx_d, __pyx_n_s_LanguageModel, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 214; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (PyDict_SetItem(__pyx_d, __pyx_n_s_LanguageModel, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 260; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
diff --git a/python/kenlm.pyx b/python/kenlm.pyx
index 5b6863a..549a780 100644
--- a/python/kenlm.pyx
+++ b/python/kenlm.pyx
@@ -184,7 +184,7 @@ cdef class Model:
Compute perplexity of a sentence.
@param sentence One full sentence to score. Do not include <s> or </s>.
"""
- words = len(to_str(sentence).split()) + 1 # For </s>
+ words = len(as_str(sentence).split()) + 1 # For </s>
return 10.0**(-self.score(sentence) / words)
def full_scores(self, sentence, bos = True, eos = True):