summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorVictor Chahuneau <vchahune@cs.cmu.edu>2012-06-06 01:10:49 -0400
committerVictor Chahuneau <vchahune@cs.cmu.edu>2012-06-06 01:10:49 -0400
commit34c2c129a376abfc79e76cf2fa1282b89ef605b6 (patch)
treed007e4928c4ccfc93fe34eb0934667865385d1ab /python
parent98e13188c40adf13b73ca994d3410f3e87d20355 (diff)
Python - Added hypergraph functionnality
- k-best translations - 1-best, k-best structures - sample derivations from the forest - intersect hypergraph and lattice - lattice
Diffstat (limited to 'python')
-rw-r--r--python/cdec/__init__.py2
-rw-r--r--python/src/_cdec.cpp2451
-rw-r--r--python/src/_cdec.pyx87
-rw-r--r--python/src/hypergraph.pxd35
-rw-r--r--python/src/kbest.pxd16
-rw-r--r--python/src/lattice.pxd16
-rw-r--r--python/src/utils.pxd38
-rw-r--r--python/test.py34
8 files changed, 2428 insertions, 251 deletions
diff --git a/python/cdec/__init__.py b/python/cdec/__init__.py
index 910140d6..c821f860 100644
--- a/python/cdec/__init__.py
+++ b/python/cdec/__init__.py
@@ -1 +1 @@
-from _cdec import Decoder, Hypergraph
+from _cdec import Decoder, Hypergraph, Lattice
diff --git a/python/src/_cdec.cpp b/python/src/_cdec.cpp
index a668912f..e1b0f20e 100644
--- a/python/src/_cdec.cpp
+++ b/python/src/_cdec.cpp
@@ -1,4 +1,4 @@
-/* Generated by Cython 0.15.1 on Mon Jun 4 01:31:27 2012 */
+/* Generated by Cython 0.15.1 on Wed Jun 6 01:04:37 2012 */
#define PY_SSIZE_T_CLEAN
#include "Python.h"
@@ -235,17 +235,26 @@
#include <string>
#include <vector>
#include <iostream>
-#include "utils/filelib.h"
#include "utils/weights.h"
+#include "utils/logval.h"
+#include "utils/prob.h"
#include "utils/wordid.h"
+#include "utils/sparse_vector.h"
#include "utils/tdict.cc"
#include "utils/verbose.h"
#include "utils/fdict.h"
+#include "utils/filelib.h"
+#include "utils/sampler.h"
+#include "decoder/lattice.h"
#include "decoder/hg.h"
#include "decoder/viterbi.h"
+#include "decoder/hg_io.h"
+#include "decoder/hg_intersect.h"
+#include "decoder/hg_sampler.h"
#include "decoder/ff_register.h"
#include "decoder/decoder.h"
#include "observer.h"
+#include "decoder/kbest.h"
#ifdef _OPENMP
#include <omp.h>
#endif /* _OPENMP */
@@ -339,27 +348,17 @@ static PyObject *__Pyx_Generator_Throw(PyObject *gen, PyObject *args, CYTHON_UNU
typedef PyObject *(*__pyx_generator_body_t)(PyObject *, PyObject *);
/*--- Type declarations ---*/
-struct __pyx_obj_5_cdec_Decoder;
struct __pyx_Generator_object;
-struct __pyx_obj_5_cdec___pyx_scope_struct____iter__;
+struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest_tree;
+struct __pyx_obj_5_cdec___pyx_scope_struct_3_sample;
struct __pyx_obj_5_cdec_Weights;
+struct __pyx_obj_5_cdec_Decoder;
struct __pyx_obj_5_cdec_Hypergraph;
+struct __pyx_obj_5_cdec_Lattice;
+struct __pyx_obj_5_cdec___pyx_scope_struct____iter__;
+struct __pyx_obj_5_cdec___pyx_scope_struct_1_kbest;
-/* "_cdec.pyx":35
- * yield Convert(fid).c_str(), self.weights[0][fid]
- *
- * cdef class Decoder: # <<<<<<<<<<<<<<
- * cdef decoder.Decoder* dec
- * cdef public Weights weights
- */
-struct __pyx_obj_5_cdec_Decoder {
- PyObject_HEAD
- Decoder *dec;
- struct __pyx_obj_5_cdec_Weights *weights;
-};
-
-
-/* "_cdec.pyx":30
+/* "_cdec.pyx":33
* self.weights[0][fid] = value
*
* def __iter__(self): # <<<<<<<<<<<<<<
@@ -376,16 +375,47 @@ struct __pyx_Generator_object {
PyObject *exc_traceback;
};
-struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ {
+
+/* "_cdec.pyx":120
+ * del derivations
+ *
+ * def kbest_tree(self, size): # <<<<<<<<<<<<<<
+ * assert (self.hg != NULL)
+ * cdef kb.KBestDerivations[vector[WordID], kb.ETreeTraversal]* derivations = new kb.KBestDerivations[vector[WordID], kb.ETreeTraversal](self.hg[0], size)
+ */
+struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest_tree {
struct __pyx_Generator_object __pyx_base;
- unsigned int __pyx_v_fid;
+ KBest::KBestDerivations<std::vector<WordID>,ETreeTraversal>::Derivation *__pyx_v_derivation;
+ KBest::KBestDerivations<std::vector<WordID>,ETreeTraversal> *__pyx_v_derivations;
+ unsigned int __pyx_v_k;
PyObject *__pyx_v_self;
+ PyObject *__pyx_v_sentence;
+ PyObject *__pyx_v_size;
+ unsigned int __pyx_t_0;
+ long __pyx_t_1;
+};
+
+
+/* "_cdec.pyx":137
+ * hypergraph.Intersect(lat.lattice[0], self.hg)
+ *
+ * def sample(self, unsigned n): # <<<<<<<<<<<<<<
+ * assert (self.hg != NULL)
+ * cdef vector[hypergraph.Hypothesis]* hypos = new vector[hypergraph.Hypothesis]()
+ */
+struct __pyx_obj_5_cdec___pyx_scope_struct_3_sample {
+ struct __pyx_Generator_object __pyx_base;
+ std::vector<HypergraphSampler::Hypothesis> *__pyx_v_hypos;
+ unsigned int __pyx_v_k;
+ unsigned int __pyx_v_n;
+ PyObject *__pyx_v_self;
+ PyObject *__pyx_v_sentence;
size_t __pyx_t_0;
unsigned int __pyx_t_1;
};
-/* "_cdec.pyx":12
+/* "_cdec.pyx":15
* pass
*
* cdef class Weights: # <<<<<<<<<<<<<<
@@ -398,16 +428,80 @@ struct __pyx_obj_5_cdec_Weights {
};
-/* "_cdec.pyx":82
+/* "_cdec.pyx":38
+ * yield FDConvert(fid).c_str(), self.weights[0][fid]
+ *
+ * cdef class Decoder: # <<<<<<<<<<<<<<
+ * cdef decoder.Decoder* dec
+ * cdef public Weights weights
+ */
+struct __pyx_obj_5_cdec_Decoder {
+ PyObject_HEAD
+ Decoder *dec;
+ struct __pyx_obj_5_cdec_Weights *weights;
+};
+
+
+/* "_cdec.pyx":86
* return hg
*
* cdef class Hypergraph: # <<<<<<<<<<<<<<
* cdef hypergraph.Hypergraph* hg
- *
+ * cdef MT19937* rng
*/
struct __pyx_obj_5_cdec_Hypergraph {
PyObject_HEAD
Hypergraph *hg;
+ MT19937 *rng;
+};
+
+
+/* "_cdec.pyx":154
+ * # TODO: inside-outside pruning
+ *
+ * cdef class Lattice: # <<<<<<<<<<<<<<
+ * cdef lattice.Lattice* lattice
+ *
+ */
+struct __pyx_obj_5_cdec_Lattice {
+ PyObject_HEAD
+ Lattice *lattice;
+};
+
+
+/* "_cdec.pyx":33
+ * self.weights[0][fid] = value
+ *
+ * def __iter__(self): # <<<<<<<<<<<<<<
+ * cdef unsigned fid
+ * for fid in range(1, self.weights.size()):
+ */
+struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ {
+ struct __pyx_Generator_object __pyx_base;
+ unsigned int __pyx_v_fid;
+ PyObject *__pyx_v_self;
+ size_t __pyx_t_0;
+ unsigned int __pyx_t_1;
+};
+
+
+/* "_cdec.pyx":107
+ * return tree.decode('utf8')
+ *
+ * def kbest(self, size): # <<<<<<<<<<<<<<
+ * assert (self.hg != NULL)
+ * cdef kb.KBestDerivations[vector[WordID], kb.ESentenceTraversal]* derivations = new kb.KBestDerivations[vector[WordID], kb.ESentenceTraversal](self.hg[0], size)
+ */
+struct __pyx_obj_5_cdec___pyx_scope_struct_1_kbest {
+ struct __pyx_Generator_object __pyx_base;
+ KBest::KBestDerivations<std::vector<WordID>,ESentenceTraversal>::Derivation *__pyx_v_derivation;
+ KBest::KBestDerivations<std::vector<WordID>,ESentenceTraversal> *__pyx_v_derivations;
+ unsigned int __pyx_v_k;
+ PyObject *__pyx_v_self;
+ PyObject *__pyx_v_size;
+ PyObject *__pyx_v_tree;
+ unsigned int __pyx_t_0;
+ long __pyx_t_1;
};
@@ -543,16 +637,24 @@ static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); /*proto*/
/* Module declarations from 'utils' */
+/* Module declarations from 'lattice' */
+
/* Module declarations from 'hypergraph' */
/* Module declarations from 'decoder' */
+/* Module declarations from 'kbest' */
+
/* Module declarations from '_cdec' */
static PyTypeObject *__pyx_ptype_5_cdec_Weights = 0;
static PyTypeObject *__pyx_ptype_5_cdec_Decoder = 0;
static PyTypeObject *__pyx_ptype_5_cdec_Hypergraph = 0;
+static PyTypeObject *__pyx_ptype_5_cdec_Lattice = 0;
static PyTypeObject *__pyx_ptype_5_cdec___pyx_Generator = 0;
static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct____iter__ = 0;
+static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_1_kbest = 0;
+static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_2_kbest_tree = 0;
+static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_3_sample = 0;
#define __Pyx_MODULE_NAME "_cdec"
int __pyx_module_is_main__cdec = 0;
@@ -561,8 +663,10 @@ static PyObject *__pyx_builtin_Exception;
static PyObject *__pyx_builtin_KeyError;
static PyObject *__pyx_builtin_range;
static PyObject *__pyx_builtin_open;
+static PyObject *__pyx_builtin_eval;
static char __pyx_k_1[] = "#";
static char __pyx_k_3[] = "=";
+static char __pyx_k__eval[] = "eval";
static char __pyx_k__open[] = "open";
static char __pyx_k__utf8[] = "utf8";
static char __pyx_k___cdec[] = "_cdec";
@@ -581,6 +685,7 @@ static char __pyx_k____test__[] = "__test__";
static char __pyx_k__sentence[] = "sentence";
static char __pyx_k__Exception[] = "Exception";
static char __pyx_k____enter__[] = "__enter__";
+static char __pyx_k__plf_tuple[] = "plf_tuple";
static char __pyx_k__fromconfig[] = "fromconfig";
static char __pyx_k__startswith[] = "startswith";
static char __pyx_k__ParseFailed[] = "ParseFailed";
@@ -598,9 +703,11 @@ static PyObject *__pyx_n_s__config;
static PyObject *__pyx_n_s__decode;
static PyObject *__pyx_n_s__decoder;
static PyObject *__pyx_n_s__encode;
+static PyObject *__pyx_n_s__eval;
static PyObject *__pyx_n_s__fromconfig;
static PyObject *__pyx_n_s__grammar;
static PyObject *__pyx_n_s__open;
+static PyObject *__pyx_n_s__plf_tuple;
static PyObject *__pyx_n_s__range;
static PyObject *__pyx_n_s__sentence;
static PyObject *__pyx_n_s__split;
@@ -613,8 +720,12 @@ static PyObject *__pyx_k_tuple_5;
static PyObject *__pyx_k_tuple_6;
static PyObject *__pyx_k_tuple_7;
static PyObject *__pyx_k_tuple_8;
+static PyObject *__pyx_k_tuple_9;
+static PyObject *__pyx_k_tuple_10;
+static PyObject *__pyx_k_tuple_11;
+static PyObject *__pyx_k_tuple_12;
-/* "_cdec.pyx":15
+/* "_cdec.pyx":18
* cdef vector[weight_t]* weights
*
* def __cinit__(self, Decoder decoder): # <<<<<<<<<<<<<<
@@ -649,7 +760,7 @@ static int __pyx_pf_5_cdec_7Weights___cinit__(PyObject *__pyx_v_self, PyObject *
else goto __pyx_L5_argtuple_error;
}
if (unlikely(kw_args > 0)) {
- if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "__cinit__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "__cinit__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 18; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
}
} else if (PyTuple_GET_SIZE(__pyx_args) != 1) {
goto __pyx_L5_argtuple_error;
@@ -660,15 +771,15 @@ static int __pyx_pf_5_cdec_7Weights___cinit__(PyObject *__pyx_v_self, PyObject *
}
goto __pyx_L4_argument_unpacking_done;
__pyx_L5_argtuple_error:;
- __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 18; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
__pyx_L3_error:;
__Pyx_AddTraceback("_cdec.Weights.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
__Pyx_RefNannyFinishContext();
return -1;
__pyx_L4_argument_unpacking_done:;
- if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_decoder), __pyx_ptype_5_cdec_Decoder, 1, "decoder", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_decoder), __pyx_ptype_5_cdec_Decoder, 1, "decoder", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 18; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- /* "_cdec.pyx":16
+ /* "_cdec.pyx":19
*
* def __cinit__(self, Decoder decoder):
* self.weights = &decoder.dec.CurrentWeightVector() # <<<<<<<<<<<<<<
@@ -687,11 +798,11 @@ static int __pyx_pf_5_cdec_7Weights___cinit__(PyObject *__pyx_v_self, PyObject *
return __pyx_r;
}
-/* "_cdec.pyx":18
+/* "_cdec.pyx":21
* self.weights = &decoder.dec.CurrentWeightVector()
*
* def __getitem__(self, char* fname): # <<<<<<<<<<<<<<
- * cdef unsigned fid = Convert(fname)
+ * cdef unsigned fid = FDConvert(fname)
* if fid <= self.weights.size():
*/
@@ -709,7 +820,7 @@ static PyObject *__pyx_pf_5_cdec_7Weights_1__getitem__(PyObject *__pyx_v_self, P
int __pyx_clineno = 0;
__Pyx_RefNannySetupContext("__getitem__");
assert(__pyx_arg_fname); {
- __pyx_v_fname = PyBytes_AsString(__pyx_arg_fname); if (unlikely((!__pyx_v_fname) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 18; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ __pyx_v_fname = PyBytes_AsString(__pyx_arg_fname); if (unlikely((!__pyx_v_fname) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 21; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
}
goto __pyx_L4_argument_unpacking_done;
__pyx_L3_error:;
@@ -718,18 +829,18 @@ static PyObject *__pyx_pf_5_cdec_7Weights_1__getitem__(PyObject *__pyx_v_self, P
return NULL;
__pyx_L4_argument_unpacking_done:;
- /* "_cdec.pyx":19
+ /* "_cdec.pyx":22
*
* def __getitem__(self, char* fname):
- * cdef unsigned fid = Convert(fname) # <<<<<<<<<<<<<<
+ * cdef unsigned fid = FDConvert(fname) # <<<<<<<<<<<<<<
* if fid <= self.weights.size():
* return self.weights[0][fid]
*/
__pyx_v_fid = FD::Convert(__pyx_v_fname);
- /* "_cdec.pyx":20
+ /* "_cdec.pyx":23
* def __getitem__(self, char* fname):
- * cdef unsigned fid = Convert(fname)
+ * cdef unsigned fid = FDConvert(fname)
* if fid <= self.weights.size(): # <<<<<<<<<<<<<<
* return self.weights[0][fid]
* raise KeyError(fname)
@@ -737,15 +848,15 @@ static PyObject *__pyx_pf_5_cdec_7Weights_1__getitem__(PyObject *__pyx_v_self, P
__pyx_t_1 = (__pyx_v_fid <= ((struct __pyx_obj_5_cdec_Weights *)__pyx_v_self)->weights->size());
if (__pyx_t_1) {
- /* "_cdec.pyx":21
- * cdef unsigned fid = Convert(fname)
+ /* "_cdec.pyx":24
+ * cdef unsigned fid = FDConvert(fname)
* if fid <= self.weights.size():
* return self.weights[0][fid] # <<<<<<<<<<<<<<
* raise KeyError(fname)
*
*/
__Pyx_XDECREF(__pyx_r);
- __pyx_t_2 = PyFloat_FromDouble(((((struct __pyx_obj_5_cdec_Weights *)__pyx_v_self)->weights[0])[__pyx_v_fid])); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 21; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyFloat_FromDouble(((((struct __pyx_obj_5_cdec_Weights *)__pyx_v_self)->weights[0])[__pyx_v_fid])); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
__pyx_r = __pyx_t_2;
__pyx_t_2 = 0;
@@ -754,26 +865,26 @@ static PyObject *__pyx_pf_5_cdec_7Weights_1__getitem__(PyObject *__pyx_v_self, P
}
__pyx_L5:;
- /* "_cdec.pyx":22
+ /* "_cdec.pyx":25
* if fid <= self.weights.size():
* return self.weights[0][fid]
* raise KeyError(fname) # <<<<<<<<<<<<<<
*
* def __setitem__(self, char* fname, float value):
*/
- __pyx_t_2 = PyBytes_FromString(__pyx_v_fname); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 22; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyBytes_FromString(__pyx_v_fname); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 25; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(((PyObject *)__pyx_t_2));
- __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 22; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 25; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(((PyObject *)__pyx_t_3));
PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_t_2));
__Pyx_GIVEREF(((PyObject *)__pyx_t_2));
__pyx_t_2 = 0;
- __pyx_t_2 = PyObject_Call(__pyx_builtin_KeyError, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 22; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_Call(__pyx_builtin_KeyError, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 25; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
__Pyx_Raise(__pyx_t_2, 0, 0, 0);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 22; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 25; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__pyx_r = Py_None; __Pyx_INCREF(Py_None);
goto __pyx_L0;
@@ -788,11 +899,11 @@ static PyObject *__pyx_pf_5_cdec_7Weights_1__getitem__(PyObject *__pyx_v_self, P
return __pyx_r;
}
-/* "_cdec.pyx":24
+/* "_cdec.pyx":27
* raise KeyError(fname)
*
* def __setitem__(self, char* fname, float value): # <<<<<<<<<<<<<<
- * cdef unsigned fid = Convert(<char *>fname)
+ * cdef unsigned fid = FDConvert(<char *>fname)
* if self.weights.size() <= fid:
*/
@@ -809,10 +920,10 @@ static int __pyx_pf_5_cdec_7Weights_2__setitem__(PyObject *__pyx_v_self, PyObjec
int __pyx_clineno = 0;
__Pyx_RefNannySetupContext("__setitem__");
assert(__pyx_arg_fname); {
- __pyx_v_fname = PyBytes_AsString(__pyx_arg_fname); if (unlikely((!__pyx_v_fname) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ __pyx_v_fname = PyBytes_AsString(__pyx_arg_fname); if (unlikely((!__pyx_v_fname) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 27; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
}
assert(__pyx_arg_value); {
- __pyx_v_value = __pyx_PyFloat_AsDouble(__pyx_arg_value); if (unlikely((__pyx_v_value == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ __pyx_v_value = __pyx_PyFloat_AsDouble(__pyx_arg_value); if (unlikely((__pyx_v_value == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 27; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
}
goto __pyx_L4_argument_unpacking_done;
__pyx_L3_error:;
@@ -821,18 +932,18 @@ static int __pyx_pf_5_cdec_7Weights_2__setitem__(PyObject *__pyx_v_self, PyObjec
return -1;
__pyx_L4_argument_unpacking_done:;
- /* "_cdec.pyx":25
+ /* "_cdec.pyx":28
*
* def __setitem__(self, char* fname, float value):
- * cdef unsigned fid = Convert(<char *>fname) # <<<<<<<<<<<<<<
+ * cdef unsigned fid = FDConvert(<char *>fname) # <<<<<<<<<<<<<<
* if self.weights.size() <= fid:
* self.weights.resize(fid + 1)
*/
__pyx_v_fid = FD::Convert(((char *)__pyx_v_fname));
- /* "_cdec.pyx":26
+ /* "_cdec.pyx":29
* def __setitem__(self, char* fname, float value):
- * cdef unsigned fid = Convert(<char *>fname)
+ * cdef unsigned fid = FDConvert(<char *>fname)
* if self.weights.size() <= fid: # <<<<<<<<<<<<<<
* self.weights.resize(fid + 1)
* self.weights[0][fid] = value
@@ -840,8 +951,8 @@ static int __pyx_pf_5_cdec_7Weights_2__setitem__(PyObject *__pyx_v_self, PyObjec
__pyx_t_1 = (((struct __pyx_obj_5_cdec_Weights *)__pyx_v_self)->weights->size() <= __pyx_v_fid);
if (__pyx_t_1) {
- /* "_cdec.pyx":27
- * cdef unsigned fid = Convert(<char *>fname)
+ /* "_cdec.pyx":30
+ * cdef unsigned fid = FDConvert(<char *>fname)
* if self.weights.size() <= fid:
* self.weights.resize(fid + 1) # <<<<<<<<<<<<<<
* self.weights[0][fid] = value
@@ -852,7 +963,7 @@ static int __pyx_pf_5_cdec_7Weights_2__setitem__(PyObject *__pyx_v_self, PyObjec
}
__pyx_L5:;
- /* "_cdec.pyx":28
+ /* "_cdec.pyx":31
* if self.weights.size() <= fid:
* self.weights.resize(fid + 1)
* self.weights[0][fid] = value # <<<<<<<<<<<<<<
@@ -867,7 +978,7 @@ static int __pyx_pf_5_cdec_7Weights_2__setitem__(PyObject *__pyx_v_self, PyObjec
}
static PyObject *__pyx_gb_5_cdec_7Weights_4generator(struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *__pyx_cur_scope, PyObject *__pyx_sent_value); /* proto */
-/* "_cdec.pyx":30
+/* "_cdec.pyx":33
* self.weights[0][fid] = value
*
* def __iter__(self): # <<<<<<<<<<<<<<
@@ -921,31 +1032,31 @@ static PyObject *__pyx_gb_5_cdec_7Weights_4generator(struct __pyx_obj_5_cdec___p
return NULL;
}
__pyx_L3_first_run:;
- if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- /* "_cdec.pyx":32
+ /* "_cdec.pyx":35
* def __iter__(self):
* cdef unsigned fid
* for fid in range(1, self.weights.size()): # <<<<<<<<<<<<<<
- * yield Convert(fid).c_str(), self.weights[0][fid]
+ * yield FDConvert(fid).c_str(), self.weights[0][fid]
*
*/
__pyx_t_1 = ((struct __pyx_obj_5_cdec_Weights *)__pyx_cur_scope->__pyx_v_self)->weights->size();
for (__pyx_t_2 = 1; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) {
__pyx_cur_scope->__pyx_v_fid = __pyx_t_2;
- /* "_cdec.pyx":33
+ /* "_cdec.pyx":36
* cdef unsigned fid
* for fid in range(1, self.weights.size()):
- * yield Convert(fid).c_str(), self.weights[0][fid] # <<<<<<<<<<<<<<
+ * yield FDConvert(fid).c_str(), self.weights[0][fid] # <<<<<<<<<<<<<<
*
* cdef class Decoder:
*/
- __pyx_t_3 = PyBytes_FromString(FD::Convert(__pyx_cur_scope->__pyx_v_fid).c_str()); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = PyBytes_FromString(FD::Convert(__pyx_cur_scope->__pyx_v_fid).c_str()); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(((PyObject *)__pyx_t_3));
- __pyx_t_4 = PyFloat_FromDouble(((((struct __pyx_obj_5_cdec_Weights *)__pyx_cur_scope->__pyx_v_self)->weights[0])[__pyx_cur_scope->__pyx_v_fid])); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = PyFloat_FromDouble(((((struct __pyx_obj_5_cdec_Weights *)__pyx_cur_scope->__pyx_v_self)->weights[0])[__pyx_cur_scope->__pyx_v_fid])); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_4);
- __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(((PyObject *)__pyx_t_5));
PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_t_3));
__Pyx_GIVEREF(((PyObject *)__pyx_t_3));
@@ -965,9 +1076,9 @@ static PyObject *__pyx_gb_5_cdec_7Weights_4generator(struct __pyx_obj_5_cdec___p
__pyx_L6_resume_from_yield:;
__pyx_t_1 = __pyx_cur_scope->__pyx_t_0;
__pyx_t_2 = __pyx_cur_scope->__pyx_t_1;
- if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
}
- PyErr_SetNone(PyExc_StopIteration); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ PyErr_SetNone(PyExc_StopIteration); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
goto __pyx_L0;
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_3);
@@ -981,7 +1092,7 @@ static PyObject *__pyx_gb_5_cdec_7Weights_4generator(struct __pyx_obj_5_cdec___p
return NULL;
}
-/* "_cdec.pyx":39
+/* "_cdec.pyx":42
* cdef public Weights weights
*
* def __cinit__(self, char* config): # <<<<<<<<<<<<<<
@@ -1019,25 +1130,25 @@ static int __pyx_pf_5_cdec_7Decoder___cinit__(PyObject *__pyx_v_self, PyObject *
else goto __pyx_L5_argtuple_error;
}
if (unlikely(kw_args > 0)) {
- if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "__cinit__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "__cinit__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
}
} else if (PyTuple_GET_SIZE(__pyx_args) != 1) {
goto __pyx_L5_argtuple_error;
} else {
values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
}
- __pyx_v_config = PyBytes_AsString(values[0]); if (unlikely((!__pyx_v_config) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ __pyx_v_config = PyBytes_AsString(values[0]); if (unlikely((!__pyx_v_config) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
}
goto __pyx_L4_argument_unpacking_done;
__pyx_L5_argtuple_error:;
- __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
__pyx_L3_error:;
__Pyx_AddTraceback("_cdec.Decoder.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
__Pyx_RefNannyFinishContext();
return -1;
__pyx_L4_argument_unpacking_done:;
- /* "_cdec.pyx":40
+ /* "_cdec.pyx":43
*
* def __cinit__(self, char* config):
* decoder.register_feature_functions() # <<<<<<<<<<<<<<
@@ -1046,7 +1157,7 @@ static int __pyx_pf_5_cdec_7Decoder___cinit__(PyObject *__pyx_v_self, PyObject *
*/
register_feature_functions();
- /* "_cdec.pyx":41
+ /* "_cdec.pyx":44
* def __cinit__(self, char* config):
* decoder.register_feature_functions()
* cdef istringstream* config_stream = new istringstream(config) # ConfigStream(kwargs) # <<<<<<<<<<<<<<
@@ -1055,7 +1166,7 @@ static int __pyx_pf_5_cdec_7Decoder___cinit__(PyObject *__pyx_v_self, PyObject *
*/
__pyx_v_config_stream = new std::istringstream(__pyx_v_config);
- /* "_cdec.pyx":44
+ /* "_cdec.pyx":47
* #cdef ReadFile* config_file = new ReadFile(string(config))
* #cdef istream* config_stream = config_file.stream()
* self.dec = new decoder.Decoder(config_stream) # <<<<<<<<<<<<<<
@@ -1064,7 +1175,7 @@ static int __pyx_pf_5_cdec_7Decoder___cinit__(PyObject *__pyx_v_self, PyObject *
*/
((struct __pyx_obj_5_cdec_Decoder *)__pyx_v_self)->dec = new Decoder(__pyx_v_config_stream);
- /* "_cdec.pyx":45
+ /* "_cdec.pyx":48
* #cdef istream* config_stream = config_file.stream()
* self.dec = new decoder.Decoder(config_stream)
* del config_stream # <<<<<<<<<<<<<<
@@ -1073,19 +1184,19 @@ static int __pyx_pf_5_cdec_7Decoder___cinit__(PyObject *__pyx_v_self, PyObject *
*/
delete __pyx_v_config_stream;
- /* "_cdec.pyx":47
+ /* "_cdec.pyx":50
* del config_stream
* #del config_file
* self.weights = Weights(self) # <<<<<<<<<<<<<<
*
* def __dealloc__(self):
*/
- __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 47; __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 = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(((PyObject *)__pyx_t_1));
__Pyx_INCREF(__pyx_v_self);
PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_self);
__Pyx_GIVEREF(__pyx_v_self);
- __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_Weights)), ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_Weights)), ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
__Pyx_GIVEREF(__pyx_t_2);
@@ -1106,7 +1217,7 @@ static int __pyx_pf_5_cdec_7Decoder___cinit__(PyObject *__pyx_v_self, PyObject *
return __pyx_r;
}
-/* "_cdec.pyx":49
+/* "_cdec.pyx":52
* self.weights = Weights(self)
*
* def __dealloc__(self): # <<<<<<<<<<<<<<
@@ -1119,7 +1230,7 @@ static void __pyx_pf_5_cdec_7Decoder_1__dealloc__(PyObject *__pyx_v_self) {
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("__dealloc__");
- /* "_cdec.pyx":50
+ /* "_cdec.pyx":53
*
* def __dealloc__(self):
* del self.dec # <<<<<<<<<<<<<<
@@ -1131,7 +1242,7 @@ static void __pyx_pf_5_cdec_7Decoder_1__dealloc__(PyObject *__pyx_v_self) {
__Pyx_RefNannyFinishContext();
}
-/* "_cdec.pyx":53
+/* "_cdec.pyx":56
*
* @classmethod
* def fromconfig(cls, ini): # <<<<<<<<<<<<<<
@@ -1169,19 +1280,19 @@ static PyObject *__pyx_pf_5_cdec_7Decoder_2fromconfig(PyObject *__pyx_v_cls, PyO
int __pyx_clineno = 0;
__Pyx_RefNannySetupContext("fromconfig");
- /* "_cdec.pyx":54
+ /* "_cdec.pyx":57
* @classmethod
* def fromconfig(cls, ini):
* cdef dict config = {} # <<<<<<<<<<<<<<
* with open(ini) as fp:
* for line in fp:
*/
- __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(((PyObject *)__pyx_t_1));
__pyx_v_config = __pyx_t_1;
__pyx_t_1 = 0;
- /* "_cdec.pyx":55
+ /* "_cdec.pyx":58
* def fromconfig(cls, ini):
* cdef dict config = {}
* with open(ini) as fp: # <<<<<<<<<<<<<<
@@ -1189,20 +1300,20 @@ static PyObject *__pyx_pf_5_cdec_7Decoder_2fromconfig(PyObject *__pyx_v_cls, PyO
* line = line.strip()
*/
/*with:*/ {
- __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 55; __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 = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(((PyObject *)__pyx_t_1));
__Pyx_INCREF(__pyx_v_ini);
PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_ini);
__Pyx_GIVEREF(__pyx_v_ini);
- __pyx_t_2 = PyObject_Call(__pyx_builtin_open, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_Call(__pyx_builtin_open, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
- __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s____exit__); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s____exit__); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_3);
- __pyx_t_1 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s____enter__); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L5_error;}
+ __pyx_t_1 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s____enter__); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L5_error;}
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L5_error;}
+ __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L5_error;}
__Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
/*try:*/ {
@@ -1215,7 +1326,7 @@ static PyObject *__pyx_pf_5_cdec_7Decoder_2fromconfig(PyObject *__pyx_v_cls, PyO
__pyx_v_fp = __pyx_t_2;
__pyx_t_2 = 0;
- /* "_cdec.pyx":56
+ /* "_cdec.pyx":59
* cdef dict config = {}
* with open(ini) as fp:
* for line in fp: # <<<<<<<<<<<<<<
@@ -1226,7 +1337,7 @@ static PyObject *__pyx_pf_5_cdec_7Decoder_2fromconfig(PyObject *__pyx_v_cls, PyO
__pyx_t_2 = __pyx_v_fp; __Pyx_INCREF(__pyx_t_2); __pyx_t_7 = 0;
__pyx_t_8 = NULL;
} else {
- __pyx_t_7 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_v_fp); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
+ __pyx_t_7 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_v_fp); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
__Pyx_GOTREF(__pyx_t_2);
__pyx_t_8 = Py_TYPE(__pyx_t_2)->tp_iternext;
}
@@ -1242,7 +1353,7 @@ static PyObject *__pyx_pf_5_cdec_7Decoder_2fromconfig(PyObject *__pyx_v_cls, PyO
if (unlikely(!__pyx_t_1)) {
if (PyErr_Occurred()) {
if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear();
- else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
+ else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
}
break;
}
@@ -1252,38 +1363,38 @@ static PyObject *__pyx_pf_5_cdec_7Decoder_2fromconfig(PyObject *__pyx_v_cls, PyO
__pyx_v_line = __pyx_t_1;
__pyx_t_1 = 0;
- /* "_cdec.pyx":57
+ /* "_cdec.pyx":60
* with open(ini) as fp:
* for line in fp:
* line = line.strip() # <<<<<<<<<<<<<<
* if not line or line.startswith('#'): continue
* param, value = line.split('=')
*/
- __pyx_t_1 = PyObject_GetAttr(__pyx_v_line, __pyx_n_s__strip); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
+ __pyx_t_1 = PyObject_GetAttr(__pyx_v_line, __pyx_n_s__strip); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
__Pyx_GOTREF(__pyx_t_1);
- __pyx_t_9 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
+ __pyx_t_9 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
__Pyx_GOTREF(__pyx_t_9);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__Pyx_DECREF(__pyx_v_line);
__pyx_v_line = __pyx_t_9;
__pyx_t_9 = 0;
- /* "_cdec.pyx":58
+ /* "_cdec.pyx":61
* for line in fp:
* line = line.strip()
* if not line or line.startswith('#'): continue # <<<<<<<<<<<<<<
* param, value = line.split('=')
* config[param.strip()] = value.strip()
*/
- __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_v_line); if (unlikely(__pyx_t_10 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
+ __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_v_line); if (unlikely(__pyx_t_10 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
__pyx_t_11 = (!__pyx_t_10);
if (!__pyx_t_11) {
- __pyx_t_9 = PyObject_GetAttr(__pyx_v_line, __pyx_n_s__startswith); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
+ __pyx_t_9 = PyObject_GetAttr(__pyx_v_line, __pyx_n_s__startswith); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
__Pyx_GOTREF(__pyx_t_9);
- __pyx_t_1 = PyObject_Call(__pyx_t_9, ((PyObject *)__pyx_k_tuple_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
+ __pyx_t_1 = PyObject_Call(__pyx_t_9, ((PyObject *)__pyx_k_tuple_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
- __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_10 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
+ __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_10 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__pyx_t_12 = __pyx_t_10;
} else {
@@ -1295,16 +1406,16 @@ static PyObject *__pyx_pf_5_cdec_7Decoder_2fromconfig(PyObject *__pyx_v_cls, PyO
}
__pyx_L19:;
- /* "_cdec.pyx":59
+ /* "_cdec.pyx":62
* line = line.strip()
* if not line or line.startswith('#'): continue
* param, value = line.split('=') # <<<<<<<<<<<<<<
* config[param.strip()] = value.strip()
* return cls(**config)
*/
- __pyx_t_1 = PyObject_GetAttr(__pyx_v_line, __pyx_n_s__split); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
+ __pyx_t_1 = PyObject_GetAttr(__pyx_v_line, __pyx_n_s__split); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
__Pyx_GOTREF(__pyx_t_1);
- __pyx_t_9 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_k_tuple_4), NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
+ __pyx_t_9 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_k_tuple_4), NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
__Pyx_GOTREF(__pyx_t_9);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
if ((likely(PyTuple_CheckExact(__pyx_t_9))) || (PyList_CheckExact(__pyx_t_9))) {
@@ -1313,7 +1424,7 @@ static PyObject *__pyx_pf_5_cdec_7Decoder_2fromconfig(PyObject *__pyx_v_cls, PyO
if (unlikely(PyTuple_GET_SIZE(sequence) != 2)) {
if (PyTuple_GET_SIZE(sequence) > 2) __Pyx_RaiseTooManyValuesError(2);
else __Pyx_RaiseNeedMoreValuesError(PyTuple_GET_SIZE(sequence));
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
}
__pyx_t_1 = PyTuple_GET_ITEM(sequence, 0);
__pyx_t_13 = PyTuple_GET_ITEM(sequence, 1);
@@ -1321,7 +1432,7 @@ static PyObject *__pyx_pf_5_cdec_7Decoder_2fromconfig(PyObject *__pyx_v_cls, PyO
if (unlikely(PyList_GET_SIZE(sequence) != 2)) {
if (PyList_GET_SIZE(sequence) > 2) __Pyx_RaiseTooManyValuesError(2);
else __Pyx_RaiseNeedMoreValuesError(PyList_GET_SIZE(sequence));
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
}
__pyx_t_1 = PyList_GET_ITEM(sequence, 0);
__pyx_t_13 = PyList_GET_ITEM(sequence, 1);
@@ -1331,7 +1442,7 @@ static PyObject *__pyx_pf_5_cdec_7Decoder_2fromconfig(PyObject *__pyx_v_cls, PyO
__Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
} else {
Py_ssize_t index = -1;
- __pyx_t_14 = PyObject_GetIter(__pyx_t_9); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
+ __pyx_t_14 = PyObject_GetIter(__pyx_t_9); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
__Pyx_GOTREF(__pyx_t_14);
__Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
__pyx_t_15 = Py_TYPE(__pyx_t_14)->tp_iternext;
@@ -1339,14 +1450,14 @@ static PyObject *__pyx_pf_5_cdec_7Decoder_2fromconfig(PyObject *__pyx_v_cls, PyO
__Pyx_GOTREF(__pyx_t_1);
index = 1; __pyx_t_13 = __pyx_t_15(__pyx_t_14); if (unlikely(!__pyx_t_13)) goto __pyx_L20_unpacking_failed;
__Pyx_GOTREF(__pyx_t_13);
- if (__Pyx_IternextUnpackEndCheck(__pyx_t_15(__pyx_t_14), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
+ if (__Pyx_IternextUnpackEndCheck(__pyx_t_15(__pyx_t_14), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
__Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
goto __pyx_L21_unpacking_done;
__pyx_L20_unpacking_failed:;
__Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_StopIteration)) PyErr_Clear();
if (!PyErr_Occurred()) __Pyx_RaiseNeedMoreValuesError(index);
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
__pyx_L21_unpacking_done:;
}
__Pyx_XDECREF(__pyx_v_param);
@@ -1356,24 +1467,24 @@ static PyObject *__pyx_pf_5_cdec_7Decoder_2fromconfig(PyObject *__pyx_v_cls, PyO
__pyx_v_value = __pyx_t_13;
__pyx_t_13 = 0;
- /* "_cdec.pyx":60
+ /* "_cdec.pyx":63
* if not line or line.startswith('#'): continue
* param, value = line.split('=')
* config[param.strip()] = value.strip() # <<<<<<<<<<<<<<
* return cls(**config)
*
*/
- __pyx_t_9 = PyObject_GetAttr(__pyx_v_value, __pyx_n_s__strip); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
+ __pyx_t_9 = PyObject_GetAttr(__pyx_v_value, __pyx_n_s__strip); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
__Pyx_GOTREF(__pyx_t_9);
- __pyx_t_13 = PyObject_Call(__pyx_t_9, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
+ __pyx_t_13 = PyObject_Call(__pyx_t_9, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
__Pyx_GOTREF(__pyx_t_13);
__Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
- __pyx_t_9 = PyObject_GetAttr(__pyx_v_param, __pyx_n_s__strip); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
+ __pyx_t_9 = PyObject_GetAttr(__pyx_v_param, __pyx_n_s__strip); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
__Pyx_GOTREF(__pyx_t_9);
- __pyx_t_1 = PyObject_Call(__pyx_t_9, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
+ __pyx_t_1 = PyObject_Call(__pyx_t_9, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
- if (PyDict_SetItem(((PyObject *)__pyx_v_config), __pyx_t_1, __pyx_t_13) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
+ if (PyDict_SetItem(((PyObject *)__pyx_v_config), __pyx_t_1, __pyx_t_13) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
__pyx_L17_continue:;
@@ -1391,7 +1502,7 @@ static PyObject *__pyx_pf_5_cdec_7Decoder_2fromconfig(PyObject *__pyx_v_cls, PyO
__Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
__Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
- /* "_cdec.pyx":55
+ /* "_cdec.pyx":58
* def fromconfig(cls, ini):
* cdef dict config = {}
* with open(ini) as fp: # <<<<<<<<<<<<<<
@@ -1400,11 +1511,11 @@ static PyObject *__pyx_pf_5_cdec_7Decoder_2fromconfig(PyObject *__pyx_v_cls, PyO
*/
/*except:*/ {
__Pyx_AddTraceback("_cdec.Decoder.fromconfig", __pyx_clineno, __pyx_lineno, __pyx_filename);
- if (__Pyx_GetException(&__pyx_t_2, &__pyx_t_13, &__pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L11_except_error;}
+ if (__Pyx_GetException(&__pyx_t_2, &__pyx_t_13, &__pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L11_except_error;}
__Pyx_GOTREF(__pyx_t_2);
__Pyx_GOTREF(__pyx_t_13);
__Pyx_GOTREF(__pyx_t_1);
- __pyx_t_9 = PyTuple_New(3); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L11_except_error;}
+ __pyx_t_9 = PyTuple_New(3); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L11_except_error;}
__Pyx_GOTREF(((PyObject *)__pyx_t_9));
__Pyx_INCREF(__pyx_t_2);
PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_2);
@@ -1417,11 +1528,11 @@ static PyObject *__pyx_pf_5_cdec_7Decoder_2fromconfig(PyObject *__pyx_v_cls, PyO
__Pyx_GIVEREF(__pyx_t_1);
__pyx_t_16 = PyObject_Call(__pyx_t_3, __pyx_t_9, NULL);
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- if (unlikely(!__pyx_t_16)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L11_except_error;}
+ if (unlikely(!__pyx_t_16)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L11_except_error;}
__Pyx_GOTREF(__pyx_t_16);
__pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_t_16);
__Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
- if (unlikely(__pyx_t_12 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L11_except_error;}
+ if (unlikely(__pyx_t_12 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L11_except_error;}
__pyx_t_11 = (!__pyx_t_12);
if (__pyx_t_11) {
__Pyx_GIVEREF(__pyx_t_2);
@@ -1429,7 +1540,7 @@ static PyObject *__pyx_pf_5_cdec_7Decoder_2fromconfig(PyObject *__pyx_v_cls, PyO
__Pyx_GIVEREF(__pyx_t_1);
__Pyx_ErrRestore(__pyx_t_2, __pyx_t_13, __pyx_t_1);
__pyx_t_2 = 0; __pyx_t_13 = 0; __pyx_t_1 = 0;
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L11_except_error;}
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L11_except_error;}
goto __pyx_L24;
}
__pyx_L24:;
@@ -1457,11 +1568,11 @@ static PyObject *__pyx_pf_5_cdec_7Decoder_2fromconfig(PyObject *__pyx_v_cls, PyO
if (__pyx_t_3) {
__pyx_t_6 = PyObject_Call(__pyx_t_3, __pyx_k_tuple_5, NULL);
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_6);
__pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_6);
__Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
- if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
}
}
goto __pyx_L25;
@@ -1471,7 +1582,7 @@ static PyObject *__pyx_pf_5_cdec_7Decoder_2fromconfig(PyObject *__pyx_v_cls, PyO
__pyx_L25:;
}
- /* "_cdec.pyx":61
+ /* "_cdec.pyx":64
* param, value = line.split('=')
* config[param.strip()] = value.strip()
* return cls(**config) # <<<<<<<<<<<<<<
@@ -1479,7 +1590,7 @@ static PyObject *__pyx_pf_5_cdec_7Decoder_2fromconfig(PyObject *__pyx_v_cls, PyO
* def read_weights(self, cfg):
*/
__Pyx_XDECREF(__pyx_r);
- __pyx_t_1 = PyEval_CallObjectWithKeywords(__pyx_v_cls, ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_v_config)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_1 = PyEval_CallObjectWithKeywords(__pyx_v_cls, ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_v_config)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
__pyx_r = __pyx_t_1;
__pyx_t_1 = 0;
@@ -1506,7 +1617,7 @@ static PyObject *__pyx_pf_5_cdec_7Decoder_2fromconfig(PyObject *__pyx_v_cls, PyO
return __pyx_r;
}
-/* "_cdec.pyx":63
+/* "_cdec.pyx":66
* return cls(**config)
*
* def read_weights(self, cfg): # <<<<<<<<<<<<<<
@@ -1543,7 +1654,7 @@ static PyObject *__pyx_pf_5_cdec_7Decoder_3read_weights(PyObject *__pyx_v_self,
int __pyx_clineno = 0;
__Pyx_RefNannySetupContext("read_weights");
- /* "_cdec.pyx":64
+ /* "_cdec.pyx":67
*
* def read_weights(self, cfg):
* with open(cfg) as fp: # <<<<<<<<<<<<<<
@@ -1551,20 +1662,20 @@ static PyObject *__pyx_pf_5_cdec_7Decoder_3read_weights(PyObject *__pyx_v_self,
* fname, value = line.split()
*/
/*with:*/ {
- __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; __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 = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(((PyObject *)__pyx_t_1));
__Pyx_INCREF(__pyx_v_cfg);
PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_cfg);
__Pyx_GIVEREF(__pyx_v_cfg);
- __pyx_t_2 = PyObject_Call(__pyx_builtin_open, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_Call(__pyx_builtin_open, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
- __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s____exit__); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s____exit__); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_3);
- __pyx_t_1 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s____enter__); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L5_error;}
+ __pyx_t_1 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s____enter__); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L5_error;}
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L5_error;}
+ __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L5_error;}
__Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
/*try:*/ {
@@ -1577,7 +1688,7 @@ static PyObject *__pyx_pf_5_cdec_7Decoder_3read_weights(PyObject *__pyx_v_self,
__pyx_v_fp = __pyx_t_2;
__pyx_t_2 = 0;
- /* "_cdec.pyx":65
+ /* "_cdec.pyx":68
* def read_weights(self, cfg):
* with open(cfg) as fp:
* for line in fp: # <<<<<<<<<<<<<<
@@ -1588,7 +1699,7 @@ static PyObject *__pyx_pf_5_cdec_7Decoder_3read_weights(PyObject *__pyx_v_self,
__pyx_t_2 = __pyx_v_fp; __Pyx_INCREF(__pyx_t_2); __pyx_t_7 = 0;
__pyx_t_8 = NULL;
} else {
- __pyx_t_7 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_v_fp); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
+ __pyx_t_7 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_v_fp); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
__Pyx_GOTREF(__pyx_t_2);
__pyx_t_8 = Py_TYPE(__pyx_t_2)->tp_iternext;
}
@@ -1604,7 +1715,7 @@ static PyObject *__pyx_pf_5_cdec_7Decoder_3read_weights(PyObject *__pyx_v_self,
if (unlikely(!__pyx_t_1)) {
if (PyErr_Occurred()) {
if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear();
- else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
+ else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
}
break;
}
@@ -1614,16 +1725,16 @@ static PyObject *__pyx_pf_5_cdec_7Decoder_3read_weights(PyObject *__pyx_v_self,
__pyx_v_line = __pyx_t_1;
__pyx_t_1 = 0;
- /* "_cdec.pyx":66
+ /* "_cdec.pyx":69
* with open(cfg) as fp:
* for line in fp:
* fname, value = line.split() # <<<<<<<<<<<<<<
* self.weights[fname.strip()] = float(value)
*
*/
- __pyx_t_1 = PyObject_GetAttr(__pyx_v_line, __pyx_n_s__split); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
+ __pyx_t_1 = PyObject_GetAttr(__pyx_v_line, __pyx_n_s__split); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
__Pyx_GOTREF(__pyx_t_1);
- __pyx_t_9 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
+ __pyx_t_9 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
__Pyx_GOTREF(__pyx_t_9);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
if ((likely(PyTuple_CheckExact(__pyx_t_9))) || (PyList_CheckExact(__pyx_t_9))) {
@@ -1632,7 +1743,7 @@ static PyObject *__pyx_pf_5_cdec_7Decoder_3read_weights(PyObject *__pyx_v_self,
if (unlikely(PyTuple_GET_SIZE(sequence) != 2)) {
if (PyTuple_GET_SIZE(sequence) > 2) __Pyx_RaiseTooManyValuesError(2);
else __Pyx_RaiseNeedMoreValuesError(PyTuple_GET_SIZE(sequence));
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
}
__pyx_t_1 = PyTuple_GET_ITEM(sequence, 0);
__pyx_t_10 = PyTuple_GET_ITEM(sequence, 1);
@@ -1640,7 +1751,7 @@ static PyObject *__pyx_pf_5_cdec_7Decoder_3read_weights(PyObject *__pyx_v_self,
if (unlikely(PyList_GET_SIZE(sequence) != 2)) {
if (PyList_GET_SIZE(sequence) > 2) __Pyx_RaiseTooManyValuesError(2);
else __Pyx_RaiseNeedMoreValuesError(PyList_GET_SIZE(sequence));
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
}
__pyx_t_1 = PyList_GET_ITEM(sequence, 0);
__pyx_t_10 = PyList_GET_ITEM(sequence, 1);
@@ -1650,7 +1761,7 @@ static PyObject *__pyx_pf_5_cdec_7Decoder_3read_weights(PyObject *__pyx_v_self,
__Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
} else {
Py_ssize_t index = -1;
- __pyx_t_11 = PyObject_GetIter(__pyx_t_9); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
+ __pyx_t_11 = PyObject_GetIter(__pyx_t_9); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
__Pyx_GOTREF(__pyx_t_11);
__Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
__pyx_t_12 = Py_TYPE(__pyx_t_11)->tp_iternext;
@@ -1658,14 +1769,14 @@ static PyObject *__pyx_pf_5_cdec_7Decoder_3read_weights(PyObject *__pyx_v_self,
__Pyx_GOTREF(__pyx_t_1);
index = 1; __pyx_t_10 = __pyx_t_12(__pyx_t_11); if (unlikely(!__pyx_t_10)) goto __pyx_L19_unpacking_failed;
__Pyx_GOTREF(__pyx_t_10);
- if (__Pyx_IternextUnpackEndCheck(__pyx_t_12(__pyx_t_11), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
+ if (__Pyx_IternextUnpackEndCheck(__pyx_t_12(__pyx_t_11), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
__Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
goto __pyx_L20_unpacking_done;
__pyx_L19_unpacking_failed:;
__Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_StopIteration)) PyErr_Clear();
if (!PyErr_Occurred()) __Pyx_RaiseNeedMoreValuesError(index);
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
__pyx_L20_unpacking_done:;
}
__Pyx_XDECREF(__pyx_v_fname);
@@ -1675,22 +1786,22 @@ static PyObject *__pyx_pf_5_cdec_7Decoder_3read_weights(PyObject *__pyx_v_self,
__pyx_v_value = __pyx_t_10;
__pyx_t_10 = 0;
- /* "_cdec.pyx":67
+ /* "_cdec.pyx":70
* for line in fp:
* fname, value = line.split()
* self.weights[fname.strip()] = float(value) # <<<<<<<<<<<<<<
*
- * def translate(self, unicode sentence, grammar=None):
+ * # TODO: list, lattice translation
*/
- __pyx_t_13 = __Pyx_PyObject_AsDouble(__pyx_v_value); if (unlikely(__pyx_t_13 == ((double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
- __pyx_t_9 = PyFloat_FromDouble(__pyx_t_13); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
+ __pyx_t_13 = __Pyx_PyObject_AsDouble(__pyx_v_value); if (unlikely(__pyx_t_13 == ((double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
+ __pyx_t_9 = PyFloat_FromDouble(__pyx_t_13); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
__Pyx_GOTREF(__pyx_t_9);
- __pyx_t_10 = PyObject_GetAttr(__pyx_v_fname, __pyx_n_s__strip); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
+ __pyx_t_10 = PyObject_GetAttr(__pyx_v_fname, __pyx_n_s__strip); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
__Pyx_GOTREF(__pyx_t_10);
- __pyx_t_1 = PyObject_Call(__pyx_t_10, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
+ __pyx_t_1 = PyObject_Call(__pyx_t_10, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
- if (PyObject_SetItem(((PyObject *)((struct __pyx_obj_5_cdec_Decoder *)__pyx_v_self)->weights), __pyx_t_1, __pyx_t_9) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
+ if (PyObject_SetItem(((PyObject *)((struct __pyx_obj_5_cdec_Decoder *)__pyx_v_self)->weights), __pyx_t_1, __pyx_t_9) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L9_error;}
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
}
@@ -1707,7 +1818,7 @@ static PyObject *__pyx_pf_5_cdec_7Decoder_3read_weights(PyObject *__pyx_v_self,
__Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
__Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
- /* "_cdec.pyx":64
+ /* "_cdec.pyx":67
*
* def read_weights(self, cfg):
* with open(cfg) as fp: # <<<<<<<<<<<<<<
@@ -1716,11 +1827,11 @@ static PyObject *__pyx_pf_5_cdec_7Decoder_3read_weights(PyObject *__pyx_v_self,
*/
/*except:*/ {
__Pyx_AddTraceback("_cdec.Decoder.read_weights", __pyx_clineno, __pyx_lineno, __pyx_filename);
- if (__Pyx_GetException(&__pyx_t_2, &__pyx_t_9, &__pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L11_except_error;}
+ if (__Pyx_GetException(&__pyx_t_2, &__pyx_t_9, &__pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L11_except_error;}
__Pyx_GOTREF(__pyx_t_2);
__Pyx_GOTREF(__pyx_t_9);
__Pyx_GOTREF(__pyx_t_1);
- __pyx_t_10 = PyTuple_New(3); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L11_except_error;}
+ __pyx_t_10 = PyTuple_New(3); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L11_except_error;}
__Pyx_GOTREF(((PyObject *)__pyx_t_10));
__Pyx_INCREF(__pyx_t_2);
PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_2);
@@ -1733,11 +1844,11 @@ static PyObject *__pyx_pf_5_cdec_7Decoder_3read_weights(PyObject *__pyx_v_self,
__Pyx_GIVEREF(__pyx_t_1);
__pyx_t_15 = PyObject_Call(__pyx_t_3, __pyx_t_10, NULL);
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L11_except_error;}
+ if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L11_except_error;}
__Pyx_GOTREF(__pyx_t_15);
__pyx_t_14 = __Pyx_PyObject_IsTrue(__pyx_t_15);
__Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
- if (unlikely(__pyx_t_14 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L11_except_error;}
+ if (unlikely(__pyx_t_14 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L11_except_error;}
__pyx_t_16 = (!__pyx_t_14);
if (__pyx_t_16) {
__Pyx_GIVEREF(__pyx_t_2);
@@ -1745,7 +1856,7 @@ static PyObject *__pyx_pf_5_cdec_7Decoder_3read_weights(PyObject *__pyx_v_self,
__Pyx_GIVEREF(__pyx_t_1);
__Pyx_ErrRestore(__pyx_t_2, __pyx_t_9, __pyx_t_1);
__pyx_t_2 = 0; __pyx_t_9 = 0; __pyx_t_1 = 0;
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L11_except_error;}
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L11_except_error;}
goto __pyx_L23;
}
__pyx_L23:;
@@ -1773,11 +1884,11 @@ static PyObject *__pyx_pf_5_cdec_7Decoder_3read_weights(PyObject *__pyx_v_self,
if (__pyx_t_3) {
__pyx_t_6 = PyObject_Call(__pyx_t_3, __pyx_k_tuple_6, NULL);
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_6);
__pyx_t_16 = __Pyx_PyObject_IsTrue(__pyx_t_6);
__Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
- if (unlikely(__pyx_t_16 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (unlikely(__pyx_t_16 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
}
}
goto __pyx_L24;
@@ -1807,9 +1918,9 @@ static PyObject *__pyx_pf_5_cdec_7Decoder_3read_weights(PyObject *__pyx_v_self,
return __pyx_r;
}
-/* "_cdec.pyx":69
- * self.weights[fname.strip()] = float(value)
+/* "_cdec.pyx":73
*
+ * # TODO: list, lattice translation
* def translate(self, unicode sentence, grammar=None): # <<<<<<<<<<<<<<
* if grammar:
* self.dec.SetSentenceGrammarFromString(string(<char *> grammar))
@@ -1857,7 +1968,7 @@ static PyObject *__pyx_pf_5_cdec_7Decoder_4translate(PyObject *__pyx_v_self, PyO
}
}
if (unlikely(kw_args > 0)) {
- if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "translate") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "translate") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 73; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
}
} else {
switch (PyTuple_GET_SIZE(__pyx_args)) {
@@ -1872,59 +1983,59 @@ static PyObject *__pyx_pf_5_cdec_7Decoder_4translate(PyObject *__pyx_v_self, PyO
}
goto __pyx_L4_argument_unpacking_done;
__pyx_L5_argtuple_error:;
- __Pyx_RaiseArgtupleInvalid("translate", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ __Pyx_RaiseArgtupleInvalid("translate", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 73; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
__pyx_L3_error:;
__Pyx_AddTraceback("_cdec.Decoder.translate", __pyx_clineno, __pyx_lineno, __pyx_filename);
__Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
- if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_sentence), (&PyUnicode_Type), 1, "sentence", 1))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_sentence), (&PyUnicode_Type), 1, "sentence", 1))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 73; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- /* "_cdec.pyx":70
- *
+ /* "_cdec.pyx":74
+ * # TODO: list, lattice translation
* def translate(self, unicode sentence, grammar=None):
* if grammar: # <<<<<<<<<<<<<<
* self.dec.SetSentenceGrammarFromString(string(<char *> grammar))
* #sgml = '<seg grammar="%s">%s</seg>' % (grammar, sentence.encode('utf8'))
*/
- __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_grammar); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_grammar); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
if (__pyx_t_1) {
- /* "_cdec.pyx":71
+ /* "_cdec.pyx":75
* def translate(self, unicode sentence, grammar=None):
* if grammar:
* self.dec.SetSentenceGrammarFromString(string(<char *> grammar)) # <<<<<<<<<<<<<<
* #sgml = '<seg grammar="%s">%s</seg>' % (grammar, sentence.encode('utf8'))
* sgml = sentence.strip().encode('utf8')
*/
- __pyx_t_2 = PyBytes_AsString(__pyx_v_grammar); if (unlikely((!__pyx_t_2) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyBytes_AsString(__pyx_v_grammar); if (unlikely((!__pyx_t_2) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
((struct __pyx_obj_5_cdec_Decoder *)__pyx_v_self)->dec->SetSentenceGrammarFromString(std::string(((char *)__pyx_t_2)));
goto __pyx_L6;
}
__pyx_L6:;
- /* "_cdec.pyx":73
+ /* "_cdec.pyx":77
* self.dec.SetSentenceGrammarFromString(string(<char *> grammar))
* #sgml = '<seg grammar="%s">%s</seg>' % (grammar, sentence.encode('utf8'))
* sgml = sentence.strip().encode('utf8') # <<<<<<<<<<<<<<
* cdef decoder.BasicObserver observer = decoder.BasicObserver()
* self.dec.Decode(string(<char *>sgml), &observer)
*/
- __pyx_t_3 = PyObject_GetAttr(((PyObject *)__pyx_v_sentence), __pyx_n_s__strip); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 73; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = PyObject_GetAttr(((PyObject *)__pyx_v_sentence), __pyx_n_s__strip); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_3);
- __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 73; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_4);
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- __pyx_t_3 = PyObject_GetAttr(__pyx_t_4, __pyx_n_s__encode); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 73; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = PyObject_GetAttr(__pyx_t_4, __pyx_n_s__encode); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_3);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_k_tuple_7), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 73; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_k_tuple_7), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_4);
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
__pyx_v_sgml = __pyx_t_4;
__pyx_t_4 = 0;
- /* "_cdec.pyx":74
+ /* "_cdec.pyx":78
* #sgml = '<seg grammar="%s">%s</seg>' % (grammar, sentence.encode('utf8'))
* sgml = sentence.strip().encode('utf8')
* cdef decoder.BasicObserver observer = decoder.BasicObserver() # <<<<<<<<<<<<<<
@@ -1933,17 +2044,17 @@ static PyObject *__pyx_pf_5_cdec_7Decoder_4translate(PyObject *__pyx_v_self, PyO
*/
__pyx_v_observer = BasicObserver();
- /* "_cdec.pyx":75
+ /* "_cdec.pyx":79
* sgml = sentence.strip().encode('utf8')
* cdef decoder.BasicObserver observer = decoder.BasicObserver()
* self.dec.Decode(string(<char *>sgml), &observer) # <<<<<<<<<<<<<<
* if observer.hypergraph == NULL:
* raise ParseFailed()
*/
- __pyx_t_2 = PyBytes_AsString(__pyx_v_sgml); if (unlikely((!__pyx_t_2) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyBytes_AsString(__pyx_v_sgml); if (unlikely((!__pyx_t_2) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 79; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
((struct __pyx_obj_5_cdec_Decoder *)__pyx_v_self)->dec->Decode(std::string(((char *)__pyx_t_2)), (&__pyx_v_observer));
- /* "_cdec.pyx":76
+ /* "_cdec.pyx":80
* cdef decoder.BasicObserver observer = decoder.BasicObserver()
* self.dec.Decode(string(<char *>sgml), &observer)
* if observer.hypergraph == NULL: # <<<<<<<<<<<<<<
@@ -1953,38 +2064,38 @@ static PyObject *__pyx_pf_5_cdec_7Decoder_4translate(PyObject *__pyx_v_self, PyO
__pyx_t_1 = (__pyx_v_observer.hypergraph == NULL);
if (__pyx_t_1) {
- /* "_cdec.pyx":77
+ /* "_cdec.pyx":81
* self.dec.Decode(string(<char *>sgml), &observer)
* if observer.hypergraph == NULL:
* raise ParseFailed() # <<<<<<<<<<<<<<
* cdef Hypergraph hg = Hypergraph()
* hg.hg = new hypergraph.Hypergraph(observer.hypergraph[0])
*/
- __pyx_t_4 = __Pyx_GetName(__pyx_m, __pyx_n_s__ParseFailed); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_4 = __Pyx_GetName(__pyx_m, __pyx_n_s__ParseFailed); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 81; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_4);
- __pyx_t_3 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 81; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_3);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
__Pyx_Raise(__pyx_t_3, 0, 0, 0);
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 81; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
goto __pyx_L7;
}
__pyx_L7:;
- /* "_cdec.pyx":78
+ /* "_cdec.pyx":82
* if observer.hypergraph == NULL:
* raise ParseFailed()
* cdef Hypergraph hg = Hypergraph() # <<<<<<<<<<<<<<
* hg.hg = new hypergraph.Hypergraph(observer.hypergraph[0])
* return hg
*/
- __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_Hypergraph)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_Hypergraph)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_3);
__pyx_v_hg = ((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_t_3);
__pyx_t_3 = 0;
- /* "_cdec.pyx":79
+ /* "_cdec.pyx":83
* raise ParseFailed()
* cdef Hypergraph hg = Hypergraph()
* hg.hg = new hypergraph.Hypergraph(observer.hypergraph[0]) # <<<<<<<<<<<<<<
@@ -1993,7 +2104,7 @@ static PyObject *__pyx_pf_5_cdec_7Decoder_4translate(PyObject *__pyx_v_self, PyO
*/
__pyx_v_hg->hg = new Hypergraph((__pyx_v_observer.hypergraph[0]));
- /* "_cdec.pyx":80
+ /* "_cdec.pyx":84
* cdef Hypergraph hg = Hypergraph()
* hg.hg = new hypergraph.Hypergraph(observer.hypergraph[0])
* return hg # <<<<<<<<<<<<<<
@@ -2020,7 +2131,7 @@ static PyObject *__pyx_pf_5_cdec_7Decoder_4translate(PyObject *__pyx_v_self, PyO
return __pyx_r;
}
-/* "_cdec.pyx":37
+/* "_cdec.pyx":40
* cdef class Decoder:
* cdef decoder.Decoder* dec
* cdef public Weights weights # <<<<<<<<<<<<<<
@@ -2053,7 +2164,7 @@ static int __pyx_pf_5_cdec_7Decoder_7weights_1__set__(PyObject *__pyx_v_self, Py
const char *__pyx_filename = NULL;
int __pyx_clineno = 0;
__Pyx_RefNannySetupContext("__set__");
- if (!(likely(((__pyx_v_value) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_value, __pyx_ptype_5_cdec_Weights))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 37; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (!(likely(((__pyx_v_value) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_value, __pyx_ptype_5_cdec_Weights))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_INCREF(__pyx_v_value);
__Pyx_GIVEREF(__pyx_v_value);
__Pyx_GOTREF(((struct __pyx_obj_5_cdec_Decoder *)__pyx_v_self)->weights);
@@ -2086,16 +2197,64 @@ static int __pyx_pf_5_cdec_7Decoder_7weights_2__del__(PyObject *__pyx_v_self) {
return __pyx_r;
}
-/* "_cdec.pyx":85
- * cdef hypergraph.Hypergraph* hg
+/* "_cdec.pyx":90
+ * cdef MT19937* rng
+ *
+ * def __dealloc__(self): # <<<<<<<<<<<<<<
+ * del self.hg
+ * if self.rng != NULL:
+ */
+
+static void __pyx_pf_5_cdec_10Hypergraph___dealloc__(PyObject *__pyx_v_self); /*proto*/
+static void __pyx_pf_5_cdec_10Hypergraph___dealloc__(PyObject *__pyx_v_self) {
+ __Pyx_RefNannyDeclarations
+ int __pyx_t_1;
+ __Pyx_RefNannySetupContext("__dealloc__");
+
+ /* "_cdec.pyx":91
+ *
+ * def __dealloc__(self):
+ * del self.hg # <<<<<<<<<<<<<<
+ * if self.rng != NULL:
+ * del self.rng
+ */
+ delete ((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_v_self)->hg;
+
+ /* "_cdec.pyx":92
+ * def __dealloc__(self):
+ * del self.hg
+ * if self.rng != NULL: # <<<<<<<<<<<<<<
+ * del self.rng
+ *
+ */
+ __pyx_t_1 = (((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_v_self)->rng != NULL);
+ if (__pyx_t_1) {
+
+ /* "_cdec.pyx":93
+ * del self.hg
+ * if self.rng != NULL:
+ * del self.rng # <<<<<<<<<<<<<<
+ *
+ * def viterbi(self):
+ */
+ delete ((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_v_self)->rng;
+ goto __pyx_L5;
+ }
+ __pyx_L5:;
+
+ __Pyx_RefNannyFinishContext();
+}
+
+/* "_cdec.pyx":95
+ * del self.rng
*
* def viterbi(self): # <<<<<<<<<<<<<<
* assert (self.hg != NULL)
* cdef vector[WordID] trans
*/
-static PyObject *__pyx_pf_5_cdec_10Hypergraph_viterbi(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
-static PyObject *__pyx_pf_5_cdec_10Hypergraph_viterbi(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
+static PyObject *__pyx_pf_5_cdec_10Hypergraph_1viterbi(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
+static PyObject *__pyx_pf_5_cdec_10Hypergraph_1viterbi(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
std::vector<WordID> __pyx_v_trans;
PyObject *__pyx_v_sentence = 0;
PyObject *__pyx_r = NULL;
@@ -2107,7 +2266,7 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_viterbi(PyObject *__pyx_v_self, CY
int __pyx_clineno = 0;
__Pyx_RefNannySetupContext("viterbi");
- /* "_cdec.pyx":86
+ /* "_cdec.pyx":96
*
* def viterbi(self):
* assert (self.hg != NULL) # <<<<<<<<<<<<<<
@@ -2117,11 +2276,11 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_viterbi(PyObject *__pyx_v_self, CY
#ifndef CYTHON_WITHOUT_ASSERTIONS
if (unlikely(!(((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_v_self)->hg != NULL))) {
PyErr_SetNone(PyExc_AssertionError);
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 96; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
}
#endif
- /* "_cdec.pyx":88
+ /* "_cdec.pyx":98
* assert (self.hg != NULL)
* cdef vector[WordID] trans
* hypergraph.ViterbiESentence(self.hg[0], &trans) # <<<<<<<<<<<<<<
@@ -2130,30 +2289,30 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_viterbi(PyObject *__pyx_v_self, CY
*/
ViterbiESentence((((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_v_self)->hg[0]), (&__pyx_v_trans));
- /* "_cdec.pyx":89
+ /* "_cdec.pyx":99
* cdef vector[WordID] trans
* hypergraph.ViterbiESentence(self.hg[0], &trans)
* cdef str sentence = GetString(trans).c_str() # <<<<<<<<<<<<<<
* return sentence.decode('utf8')
*
*/
- __pyx_t_1 = PyBytes_FromString(TD::GetString(__pyx_v_trans).c_str()); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 89; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_1 = PyBytes_FromString(TD::GetString(__pyx_v_trans).c_str()); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 99; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(((PyObject *)__pyx_t_1));
- if (!(likely(PyString_CheckExact(((PyObject *)__pyx_t_1)))||(PyErr_Format(PyExc_TypeError, "Expected str, got %.200s", Py_TYPE(((PyObject *)__pyx_t_1))->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 89; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (!(likely(PyString_CheckExact(((PyObject *)__pyx_t_1)))||(PyErr_Format(PyExc_TypeError, "Expected str, got %.200s", Py_TYPE(((PyObject *)__pyx_t_1))->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 99; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__pyx_v_sentence = ((PyObject*)__pyx_t_1);
__pyx_t_1 = 0;
- /* "_cdec.pyx":90
+ /* "_cdec.pyx":100
* hypergraph.ViterbiESentence(self.hg[0], &trans)
* cdef str sentence = GetString(trans).c_str()
* return sentence.decode('utf8') # <<<<<<<<<<<<<<
*
- * """
+ * def viterbi_tree(self):
*/
__Pyx_XDECREF(__pyx_r);
- __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_sentence), __pyx_n_s__decode); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_sentence), __pyx_n_s__decode); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
- __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_k_tuple_8), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_k_tuple_8), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__pyx_r = __pyx_t_2;
@@ -2174,6 +2333,943 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_viterbi(PyObject *__pyx_v_self, CY
return __pyx_r;
}
+/* "_cdec.pyx":102
+ * return sentence.decode('utf8')
+ *
+ * def viterbi_tree(self): # <<<<<<<<<<<<<<
+ * assert (self.hg != NULL)
+ * cdef str tree = hypergraph.ViterbiETree(self.hg[0]).c_str()
+ */
+
+static PyObject *__pyx_pf_5_cdec_10Hypergraph_2viterbi_tree(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
+static PyObject *__pyx_pf_5_cdec_10Hypergraph_2viterbi_tree(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
+ PyObject *__pyx_v_tree = 0;
+ PyObject *__pyx_r = NULL;
+ __Pyx_RefNannyDeclarations
+ PyObject *__pyx_t_1 = NULL;
+ PyObject *__pyx_t_2 = NULL;
+ int __pyx_lineno = 0;
+ const char *__pyx_filename = NULL;
+ int __pyx_clineno = 0;
+ __Pyx_RefNannySetupContext("viterbi_tree");
+
+ /* "_cdec.pyx":103
+ *
+ * def viterbi_tree(self):
+ * assert (self.hg != NULL) # <<<<<<<<<<<<<<
+ * cdef str tree = hypergraph.ViterbiETree(self.hg[0]).c_str()
+ * return tree.decode('utf8')
+ */
+ #ifndef CYTHON_WITHOUT_ASSERTIONS
+ if (unlikely(!(((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_v_self)->hg != NULL))) {
+ PyErr_SetNone(PyExc_AssertionError);
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 103; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ }
+ #endif
+
+ /* "_cdec.pyx":104
+ * def viterbi_tree(self):
+ * assert (self.hg != NULL)
+ * cdef str tree = hypergraph.ViterbiETree(self.hg[0]).c_str() # <<<<<<<<<<<<<<
+ * return tree.decode('utf8')
+ *
+ */
+ __pyx_t_1 = PyBytes_FromString(ViterbiETree((((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_v_self)->hg[0])).c_str()); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 104; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_1));
+ if (!(likely(PyString_CheckExact(((PyObject *)__pyx_t_1)))||(PyErr_Format(PyExc_TypeError, "Expected str, got %.200s", Py_TYPE(((PyObject *)__pyx_t_1))->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 104; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_v_tree = ((PyObject*)__pyx_t_1);
+ __pyx_t_1 = 0;
+
+ /* "_cdec.pyx":105
+ * assert (self.hg != NULL)
+ * cdef str tree = hypergraph.ViterbiETree(self.hg[0]).c_str()
+ * return tree.decode('utf8') # <<<<<<<<<<<<<<
+ *
+ * def kbest(self, size):
+ */
+ __Pyx_XDECREF(__pyx_r);
+ __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_tree), __pyx_n_s__decode); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_1);
+ __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_k_tuple_9), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+ __pyx_r = __pyx_t_2;
+ __pyx_t_2 = 0;
+ goto __pyx_L0;
+
+ __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+ goto __pyx_L0;
+ __pyx_L1_error:;
+ __Pyx_XDECREF(__pyx_t_1);
+ __Pyx_XDECREF(__pyx_t_2);
+ __Pyx_AddTraceback("_cdec.Hypergraph.viterbi_tree", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_r = NULL;
+ __pyx_L0:;
+ __Pyx_XDECREF(__pyx_v_tree);
+ __Pyx_XGIVEREF(__pyx_r);
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+static PyObject *__pyx_gb_5_cdec_10Hypergraph_4generator1(struct __pyx_obj_5_cdec___pyx_scope_struct_1_kbest *__pyx_cur_scope, PyObject *__pyx_sent_value); /* proto */
+
+/* "_cdec.pyx":107
+ * return tree.decode('utf8')
+ *
+ * def kbest(self, size): # <<<<<<<<<<<<<<
+ * assert (self.hg != NULL)
+ * cdef kb.KBestDerivations[vector[WordID], kb.ESentenceTraversal]* derivations = new kb.KBestDerivations[vector[WordID], kb.ESentenceTraversal](self.hg[0], size)
+ */
+
+static PyObject *__pyx_pf_5_cdec_10Hypergraph_3kbest(PyObject *__pyx_v_self, PyObject *__pyx_v_size); /*proto*/
+static PyObject *__pyx_pf_5_cdec_10Hypergraph_3kbest(PyObject *__pyx_v_self, PyObject *__pyx_v_size) {
+ struct __pyx_obj_5_cdec___pyx_scope_struct_1_kbest *__pyx_cur_scope;
+ PyObject *__pyx_r = NULL;
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("kbest");
+ __pyx_cur_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_1_kbest *)__pyx_ptype_5_cdec___pyx_scope_struct_1_kbest->tp_new(__pyx_ptype_5_cdec___pyx_scope_struct_1_kbest, __pyx_empty_tuple, NULL);
+ if (unlikely(!__pyx_cur_scope)) {
+ __Pyx_RefNannyFinishContext();
+ return NULL;
+ }
+ __Pyx_GOTREF(__pyx_cur_scope);
+ __Pyx_INCREF(__pyx_v_self);
+ __pyx_cur_scope->__pyx_v_self = __pyx_v_self;
+ __Pyx_INCREF(__pyx_v_size);
+ __pyx_cur_scope->__pyx_v_size = __pyx_v_size;
+ __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self);
+ __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_size);
+ __pyx_cur_scope->__pyx_base.resume_label = 0;
+ __pyx_cur_scope->__pyx_base.body = (__pyx_generator_body_t) __pyx_gb_5_cdec_10Hypergraph_4generator1;
+ __Pyx_GIVEREF(__pyx_cur_scope);
+ __Pyx_RefNannyFinishContext();
+ return (PyObject *) __pyx_cur_scope;
+
+ __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+ __Pyx_DECREF(((PyObject *)__pyx_cur_scope));
+ __Pyx_XGIVEREF(__pyx_r);
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+static PyObject *__pyx_gb_5_cdec_10Hypergraph_4generator1(struct __pyx_obj_5_cdec___pyx_scope_struct_1_kbest *__pyx_cur_scope, PyObject *__pyx_sent_value) /* generator body */
+{
+ PyObject *__pyx_r = NULL;
+ unsigned int __pyx_t_1;
+ long __pyx_t_2;
+ int __pyx_t_3;
+ PyObject *__pyx_t_4 = NULL;
+ PyObject *__pyx_t_5 = NULL;
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("None");
+ switch (__pyx_cur_scope->__pyx_base.resume_label) {
+ case 0: goto __pyx_L3_first_run;
+ case 1: goto __pyx_L7_resume_from_yield;
+ default: /* CPython raises the right error here */
+ __Pyx_RefNannyFinishContext();
+ return NULL;
+ }
+ __pyx_L3_first_run:;
+ if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+
+ /* "_cdec.pyx":108
+ *
+ * def kbest(self, size):
+ * assert (self.hg != NULL) # <<<<<<<<<<<<<<
+ * cdef kb.KBestDerivations[vector[WordID], kb.ESentenceTraversal]* derivations = new kb.KBestDerivations[vector[WordID], kb.ESentenceTraversal](self.hg[0], size)
+ * cdef kb.KBestDerivations[vector[WordID], kb.ESentenceTraversal].Derivation* derivation
+ */
+ #ifndef CYTHON_WITHOUT_ASSERTIONS
+ if (unlikely(!(((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_cur_scope->__pyx_v_self)->hg != NULL))) {
+ PyErr_SetNone(PyExc_AssertionError);
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ }
+ #endif
+
+ /* "_cdec.pyx":109
+ * def kbest(self, size):
+ * assert (self.hg != NULL)
+ * cdef kb.KBestDerivations[vector[WordID], kb.ESentenceTraversal]* derivations = new kb.KBestDerivations[vector[WordID], kb.ESentenceTraversal](self.hg[0], size) # <<<<<<<<<<<<<<
+ * cdef kb.KBestDerivations[vector[WordID], kb.ESentenceTraversal].Derivation* derivation
+ * cdef str tree
+ */
+ __pyx_t_1 = __Pyx_PyInt_AsUnsignedInt(__pyx_cur_scope->__pyx_v_size); if (unlikely((__pyx_t_1 == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 109; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_cur_scope->__pyx_v_derivations = new KBest::KBestDerivations<std::vector<WordID>,ESentenceTraversal>((((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_cur_scope->__pyx_v_self)->hg[0]), __pyx_t_1);
+
+ /* "_cdec.pyx":113
+ * cdef str tree
+ * cdef unsigned k
+ * for k in range(size): # <<<<<<<<<<<<<<
+ * derivation = derivations.LazyKthBest(self.hg.nodes_.size() - 1, k)
+ * if not derivation: break
+ */
+ __pyx_t_2 = __Pyx_PyInt_AsLong(__pyx_cur_scope->__pyx_v_size); if (unlikely((__pyx_t_2 == (long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 113; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ for (__pyx_t_1 = 0; __pyx_t_1 < __pyx_t_2; __pyx_t_1+=1) {
+ __pyx_cur_scope->__pyx_v_k = __pyx_t_1;
+
+ /* "_cdec.pyx":114
+ * cdef unsigned k
+ * for k in range(size):
+ * derivation = derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) # <<<<<<<<<<<<<<
+ * if not derivation: break
+ * tree = GetString(derivation._yield).c_str()
+ */
+ __pyx_cur_scope->__pyx_v_derivation = __pyx_cur_scope->__pyx_v_derivations->LazyKthBest((((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_cur_scope->__pyx_v_self)->hg->nodes_.size() - 1), __pyx_cur_scope->__pyx_v_k);
+
+ /* "_cdec.pyx":115
+ * for k in range(size):
+ * derivation = derivations.LazyKthBest(self.hg.nodes_.size() - 1, k)
+ * if not derivation: break # <<<<<<<<<<<<<<
+ * tree = GetString(derivation._yield).c_str()
+ * yield tree.decode('utf8')
+ */
+ __pyx_t_3 = (!(__pyx_cur_scope->__pyx_v_derivation != 0));
+ if (__pyx_t_3) {
+ goto __pyx_L5_break;
+ goto __pyx_L6;
+ }
+ __pyx_L6:;
+
+ /* "_cdec.pyx":116
+ * derivation = derivations.LazyKthBest(self.hg.nodes_.size() - 1, k)
+ * if not derivation: break
+ * tree = GetString(derivation._yield).c_str() # <<<<<<<<<<<<<<
+ * yield tree.decode('utf8')
+ * del derivations
+ */
+ __pyx_t_4 = PyBytes_FromString(TD::GetString(__pyx_cur_scope->__pyx_v_derivation->yield).c_str()); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 116; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_4));
+ if (!(likely(PyString_CheckExact(((PyObject *)__pyx_t_4)))||(PyErr_Format(PyExc_TypeError, "Expected str, got %.200s", Py_TYPE(((PyObject *)__pyx_t_4))->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 116; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_XGOTREF(((PyObject *)__pyx_cur_scope->__pyx_v_tree));
+ __Pyx_XDECREF(((PyObject *)__pyx_cur_scope->__pyx_v_tree));
+ __Pyx_GIVEREF(((PyObject *)__pyx_t_4));
+ __pyx_cur_scope->__pyx_v_tree = ((PyObject*)__pyx_t_4);
+ __pyx_t_4 = 0;
+
+ /* "_cdec.pyx":117
+ * if not derivation: break
+ * tree = GetString(derivation._yield).c_str()
+ * yield tree.decode('utf8') # <<<<<<<<<<<<<<
+ * del derivations
+ *
+ */
+ __pyx_t_4 = PyObject_GetAttr(((PyObject *)__pyx_cur_scope->__pyx_v_tree), __pyx_n_s__decode); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_4);
+ __pyx_t_5 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_k_tuple_10), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_5);
+ __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+ __pyx_r = __pyx_t_5;
+ __pyx_t_5 = 0;
+ __pyx_cur_scope->__pyx_t_0 = __pyx_t_1;
+ __pyx_cur_scope->__pyx_t_1 = __pyx_t_2;
+ __Pyx_XGIVEREF(__pyx_r);
+ __Pyx_RefNannyFinishContext();
+ /* return from generator, yielding value */
+ __pyx_cur_scope->__pyx_base.resume_label = 1;
+ return __pyx_r;
+ __pyx_L7_resume_from_yield:;
+ __pyx_t_1 = __pyx_cur_scope->__pyx_t_0;
+ __pyx_t_2 = __pyx_cur_scope->__pyx_t_1;
+ if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ }
+ __pyx_L5_break:;
+
+ /* "_cdec.pyx":118
+ * tree = GetString(derivation._yield).c_str()
+ * yield tree.decode('utf8')
+ * del derivations # <<<<<<<<<<<<<<
+ *
+ * def kbest_tree(self, size):
+ */
+ delete __pyx_cur_scope->__pyx_v_derivations;
+ PyErr_SetNone(PyExc_StopIteration); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ goto __pyx_L0;
+ __pyx_L1_error:;
+ __Pyx_XDECREF(__pyx_t_4);
+ __Pyx_XDECREF(__pyx_t_5);
+ __Pyx_AddTraceback("kbest", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_L0:;
+ __Pyx_XDECREF(__pyx_r);
+ __pyx_cur_scope->__pyx_base.resume_label = -1;
+ __Pyx_RefNannyFinishContext();
+ return NULL;
+}
+static PyObject *__pyx_gb_5_cdec_10Hypergraph_6generator2(struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest_tree *__pyx_cur_scope, PyObject *__pyx_sent_value); /* proto */
+
+/* "_cdec.pyx":120
+ * del derivations
+ *
+ * def kbest_tree(self, size): # <<<<<<<<<<<<<<
+ * assert (self.hg != NULL)
+ * cdef kb.KBestDerivations[vector[WordID], kb.ETreeTraversal]* derivations = new kb.KBestDerivations[vector[WordID], kb.ETreeTraversal](self.hg[0], size)
+ */
+
+static PyObject *__pyx_pf_5_cdec_10Hypergraph_5kbest_tree(PyObject *__pyx_v_self, PyObject *__pyx_v_size); /*proto*/
+static PyObject *__pyx_pf_5_cdec_10Hypergraph_5kbest_tree(PyObject *__pyx_v_self, PyObject *__pyx_v_size) {
+ struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest_tree *__pyx_cur_scope;
+ PyObject *__pyx_r = NULL;
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("kbest_tree");
+ __pyx_cur_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest_tree *)__pyx_ptype_5_cdec___pyx_scope_struct_2_kbest_tree->tp_new(__pyx_ptype_5_cdec___pyx_scope_struct_2_kbest_tree, __pyx_empty_tuple, NULL);
+ if (unlikely(!__pyx_cur_scope)) {
+ __Pyx_RefNannyFinishContext();
+ return NULL;
+ }
+ __Pyx_GOTREF(__pyx_cur_scope);
+ __Pyx_INCREF(__pyx_v_self);
+ __pyx_cur_scope->__pyx_v_self = __pyx_v_self;
+ __Pyx_INCREF(__pyx_v_size);
+ __pyx_cur_scope->__pyx_v_size = __pyx_v_size;
+ __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self);
+ __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_size);
+ __pyx_cur_scope->__pyx_base.resume_label = 0;
+ __pyx_cur_scope->__pyx_base.body = (__pyx_generator_body_t) __pyx_gb_5_cdec_10Hypergraph_6generator2;
+ __Pyx_GIVEREF(__pyx_cur_scope);
+ __Pyx_RefNannyFinishContext();
+ return (PyObject *) __pyx_cur_scope;
+
+ __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+ __Pyx_DECREF(((PyObject *)__pyx_cur_scope));
+ __Pyx_XGIVEREF(__pyx_r);
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+static PyObject *__pyx_gb_5_cdec_10Hypergraph_6generator2(struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest_tree *__pyx_cur_scope, PyObject *__pyx_sent_value) /* generator body */
+{
+ PyObject *__pyx_r = NULL;
+ unsigned int __pyx_t_1;
+ long __pyx_t_2;
+ int __pyx_t_3;
+ PyObject *__pyx_t_4 = NULL;
+ PyObject *__pyx_t_5 = NULL;
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("None");
+ switch (__pyx_cur_scope->__pyx_base.resume_label) {
+ case 0: goto __pyx_L3_first_run;
+ case 1: goto __pyx_L7_resume_from_yield;
+ default: /* CPython raises the right error here */
+ __Pyx_RefNannyFinishContext();
+ return NULL;
+ }
+ __pyx_L3_first_run:;
+ if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 120; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+
+ /* "_cdec.pyx":121
+ *
+ * def kbest_tree(self, size):
+ * assert (self.hg != NULL) # <<<<<<<<<<<<<<
+ * cdef kb.KBestDerivations[vector[WordID], kb.ETreeTraversal]* derivations = new kb.KBestDerivations[vector[WordID], kb.ETreeTraversal](self.hg[0], size)
+ * cdef kb.KBestDerivations[vector[WordID], kb.ETreeTraversal].Derivation* derivation
+ */
+ #ifndef CYTHON_WITHOUT_ASSERTIONS
+ if (unlikely(!(((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_cur_scope->__pyx_v_self)->hg != NULL))) {
+ PyErr_SetNone(PyExc_AssertionError);
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 121; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ }
+ #endif
+
+ /* "_cdec.pyx":122
+ * def kbest_tree(self, size):
+ * assert (self.hg != NULL)
+ * cdef kb.KBestDerivations[vector[WordID], kb.ETreeTraversal]* derivations = new kb.KBestDerivations[vector[WordID], kb.ETreeTraversal](self.hg[0], size) # <<<<<<<<<<<<<<
+ * cdef kb.KBestDerivations[vector[WordID], kb.ETreeTraversal].Derivation* derivation
+ * cdef str sentence
+ */
+ __pyx_t_1 = __Pyx_PyInt_AsUnsignedInt(__pyx_cur_scope->__pyx_v_size); if (unlikely((__pyx_t_1 == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 122; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_cur_scope->__pyx_v_derivations = new KBest::KBestDerivations<std::vector<WordID>,ETreeTraversal>((((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_cur_scope->__pyx_v_self)->hg[0]), __pyx_t_1);
+
+ /* "_cdec.pyx":126
+ * cdef str sentence
+ * cdef unsigned k
+ * for k in range(size): # <<<<<<<<<<<<<<
+ * derivation = derivations.LazyKthBest(self.hg.nodes_.size() - 1, k)
+ * if not derivation: break
+ */
+ __pyx_t_2 = __Pyx_PyInt_AsLong(__pyx_cur_scope->__pyx_v_size); if (unlikely((__pyx_t_2 == (long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 126; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ for (__pyx_t_1 = 0; __pyx_t_1 < __pyx_t_2; __pyx_t_1+=1) {
+ __pyx_cur_scope->__pyx_v_k = __pyx_t_1;
+
+ /* "_cdec.pyx":127
+ * cdef unsigned k
+ * for k in range(size):
+ * derivation = derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) # <<<<<<<<<<<<<<
+ * if not derivation: break
+ * sentence = GetString(derivation._yield).c_str()
+ */
+ __pyx_cur_scope->__pyx_v_derivation = __pyx_cur_scope->__pyx_v_derivations->LazyKthBest((((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_cur_scope->__pyx_v_self)->hg->nodes_.size() - 1), __pyx_cur_scope->__pyx_v_k);
+
+ /* "_cdec.pyx":128
+ * for k in range(size):
+ * derivation = derivations.LazyKthBest(self.hg.nodes_.size() - 1, k)
+ * if not derivation: break # <<<<<<<<<<<<<<
+ * sentence = GetString(derivation._yield).c_str()
+ * yield sentence.decode('utf8')
+ */
+ __pyx_t_3 = (!(__pyx_cur_scope->__pyx_v_derivation != 0));
+ if (__pyx_t_3) {
+ goto __pyx_L5_break;
+ goto __pyx_L6;
+ }
+ __pyx_L6:;
+
+ /* "_cdec.pyx":129
+ * derivation = derivations.LazyKthBest(self.hg.nodes_.size() - 1, k)
+ * if not derivation: break
+ * sentence = GetString(derivation._yield).c_str() # <<<<<<<<<<<<<<
+ * yield sentence.decode('utf8')
+ * del derivations
+ */
+ __pyx_t_4 = PyBytes_FromString(TD::GetString(__pyx_cur_scope->__pyx_v_derivation->yield).c_str()); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 129; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_4));
+ if (!(likely(PyString_CheckExact(((PyObject *)__pyx_t_4)))||(PyErr_Format(PyExc_TypeError, "Expected str, got %.200s", Py_TYPE(((PyObject *)__pyx_t_4))->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 129; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_XGOTREF(((PyObject *)__pyx_cur_scope->__pyx_v_sentence));
+ __Pyx_XDECREF(((PyObject *)__pyx_cur_scope->__pyx_v_sentence));
+ __Pyx_GIVEREF(((PyObject *)__pyx_t_4));
+ __pyx_cur_scope->__pyx_v_sentence = ((PyObject*)__pyx_t_4);
+ __pyx_t_4 = 0;
+
+ /* "_cdec.pyx":130
+ * if not derivation: break
+ * sentence = GetString(derivation._yield).c_str()
+ * yield sentence.decode('utf8') # <<<<<<<<<<<<<<
+ * del derivations
+ *
+ */
+ __pyx_t_4 = PyObject_GetAttr(((PyObject *)__pyx_cur_scope->__pyx_v_sentence), __pyx_n_s__decode); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 130; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_4);
+ __pyx_t_5 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_k_tuple_11), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 130; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_5);
+ __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+ __pyx_r = __pyx_t_5;
+ __pyx_t_5 = 0;
+ __pyx_cur_scope->__pyx_t_0 = __pyx_t_1;
+ __pyx_cur_scope->__pyx_t_1 = __pyx_t_2;
+ __Pyx_XGIVEREF(__pyx_r);
+ __Pyx_RefNannyFinishContext();
+ /* return from generator, yielding value */
+ __pyx_cur_scope->__pyx_base.resume_label = 1;
+ return __pyx_r;
+ __pyx_L7_resume_from_yield:;
+ __pyx_t_1 = __pyx_cur_scope->__pyx_t_0;
+ __pyx_t_2 = __pyx_cur_scope->__pyx_t_1;
+ if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 130; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ }
+ __pyx_L5_break:;
+
+ /* "_cdec.pyx":131
+ * sentence = GetString(derivation._yield).c_str()
+ * yield sentence.decode('utf8')
+ * del derivations # <<<<<<<<<<<<<<
+ *
+ * def intersect(self, Lattice lat):
+ */
+ delete __pyx_cur_scope->__pyx_v_derivations;
+ PyErr_SetNone(PyExc_StopIteration); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 120; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ goto __pyx_L0;
+ __pyx_L1_error:;
+ __Pyx_XDECREF(__pyx_t_4);
+ __Pyx_XDECREF(__pyx_t_5);
+ __Pyx_AddTraceback("kbest_tree", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_L0:;
+ __Pyx_XDECREF(__pyx_r);
+ __pyx_cur_scope->__pyx_base.resume_label = -1;
+ __Pyx_RefNannyFinishContext();
+ return NULL;
+}
+
+/* "_cdec.pyx":133
+ * del derivations
+ *
+ * def intersect(self, Lattice lat): # <<<<<<<<<<<<<<
+ * assert (self.hg != NULL)
+ * hypergraph.Intersect(lat.lattice[0], self.hg)
+ */
+
+static PyObject *__pyx_pf_5_cdec_10Hypergraph_7intersect(PyObject *__pyx_v_self, PyObject *__pyx_v_lat); /*proto*/
+static PyObject *__pyx_pf_5_cdec_10Hypergraph_7intersect(PyObject *__pyx_v_self, PyObject *__pyx_v_lat) {
+ PyObject *__pyx_r = NULL;
+ __Pyx_RefNannyDeclarations
+ int __pyx_lineno = 0;
+ const char *__pyx_filename = NULL;
+ int __pyx_clineno = 0;
+ __Pyx_RefNannySetupContext("intersect");
+ if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_lat), __pyx_ptype_5_cdec_Lattice, 1, "lat", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 133; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+
+ /* "_cdec.pyx":134
+ *
+ * def intersect(self, Lattice lat):
+ * assert (self.hg != NULL) # <<<<<<<<<<<<<<
+ * hypergraph.Intersect(lat.lattice[0], self.hg)
+ *
+ */
+ #ifndef CYTHON_WITHOUT_ASSERTIONS
+ if (unlikely(!(((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_v_self)->hg != NULL))) {
+ PyErr_SetNone(PyExc_AssertionError);
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ }
+ #endif
+
+ /* "_cdec.pyx":135
+ * def intersect(self, Lattice lat):
+ * assert (self.hg != NULL)
+ * hypergraph.Intersect(lat.lattice[0], self.hg) # <<<<<<<<<<<<<<
+ *
+ * def sample(self, unsigned n):
+ */
+ HG::Intersect((((struct __pyx_obj_5_cdec_Lattice *)__pyx_v_lat)->lattice[0]), ((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_v_self)->hg);
+
+ __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+ goto __pyx_L0;
+ __pyx_L1_error:;
+ __Pyx_AddTraceback("_cdec.Hypergraph.intersect", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_r = NULL;
+ __pyx_L0:;
+ __Pyx_XGIVEREF(__pyx_r);
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+static PyObject *__pyx_gb_5_cdec_10Hypergraph_9generator3(struct __pyx_obj_5_cdec___pyx_scope_struct_3_sample *__pyx_cur_scope, PyObject *__pyx_sent_value); /* proto */
+
+/* "_cdec.pyx":137
+ * hypergraph.Intersect(lat.lattice[0], self.hg)
+ *
+ * def sample(self, unsigned n): # <<<<<<<<<<<<<<
+ * assert (self.hg != NULL)
+ * cdef vector[hypergraph.Hypothesis]* hypos = new vector[hypergraph.Hypothesis]()
+ */
+
+static PyObject *__pyx_pf_5_cdec_10Hypergraph_8sample(PyObject *__pyx_v_self, PyObject *__pyx_arg_n); /*proto*/
+static PyObject *__pyx_pf_5_cdec_10Hypergraph_8sample(PyObject *__pyx_v_self, PyObject *__pyx_arg_n) {
+ struct __pyx_obj_5_cdec___pyx_scope_struct_3_sample *__pyx_cur_scope;
+ PyObject *__pyx_r = NULL;
+ __Pyx_RefNannyDeclarations
+ int __pyx_lineno = 0;
+ const char *__pyx_filename = NULL;
+ int __pyx_clineno = 0;
+ __Pyx_RefNannySetupContext("sample");
+ __pyx_cur_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_3_sample *)__pyx_ptype_5_cdec___pyx_scope_struct_3_sample->tp_new(__pyx_ptype_5_cdec___pyx_scope_struct_3_sample, __pyx_empty_tuple, NULL);
+ if (unlikely(!__pyx_cur_scope)) {
+ __Pyx_RefNannyFinishContext();
+ return NULL;
+ }
+ __Pyx_GOTREF(__pyx_cur_scope);
+ __Pyx_INCREF(__pyx_v_self);
+ __pyx_cur_scope->__pyx_v_self = __pyx_v_self;
+ assert(__pyx_arg_n); {
+ __pyx_cur_scope->__pyx_v_n = __Pyx_PyInt_AsUnsignedInt(__pyx_arg_n); if (unlikely((__pyx_cur_scope->__pyx_v_n == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 137; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ }
+ goto __pyx_L4_argument_unpacking_done;
+ __pyx_L3_error:;
+ __Pyx_AddTraceback("_cdec.Hypergraph.sample", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __Pyx_XDECREF((PyObject *)__pyx_cur_scope->__pyx_v_self); __pyx_cur_scope->__pyx_v_self = 0;
+ __Pyx_DECREF(((PyObject *)__pyx_cur_scope));
+ __Pyx_RefNannyFinishContext();
+ return NULL;
+ __pyx_L4_argument_unpacking_done:;
+ __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self);
+ __pyx_cur_scope->__pyx_base.resume_label = 0;
+ __pyx_cur_scope->__pyx_base.body = (__pyx_generator_body_t) __pyx_gb_5_cdec_10Hypergraph_9generator3;
+ __Pyx_GIVEREF(__pyx_cur_scope);
+ __Pyx_RefNannyFinishContext();
+ return (PyObject *) __pyx_cur_scope;
+
+ __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+ __Pyx_DECREF(((PyObject *)__pyx_cur_scope));
+ __Pyx_XGIVEREF(__pyx_r);
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+static PyObject *__pyx_gb_5_cdec_10Hypergraph_9generator3(struct __pyx_obj_5_cdec___pyx_scope_struct_3_sample *__pyx_cur_scope, PyObject *__pyx_sent_value) /* generator body */
+{
+ PyObject *__pyx_r = NULL;
+ int __pyx_t_1;
+ size_t __pyx_t_2;
+ unsigned int __pyx_t_3;
+ PyObject *__pyx_t_4 = NULL;
+ PyObject *__pyx_t_5 = NULL;
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("None");
+ switch (__pyx_cur_scope->__pyx_base.resume_label) {
+ case 0: goto __pyx_L3_first_run;
+ case 1: goto __pyx_L7_resume_from_yield;
+ default: /* CPython raises the right error here */
+ __Pyx_RefNannyFinishContext();
+ return NULL;
+ }
+ __pyx_L3_first_run:;
+ if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 137; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+
+ /* "_cdec.pyx":138
+ *
+ * def sample(self, unsigned n):
+ * assert (self.hg != NULL) # <<<<<<<<<<<<<<
+ * cdef vector[hypergraph.Hypothesis]* hypos = new vector[hypergraph.Hypothesis]()
+ * if self.rng == NULL:
+ */
+ #ifndef CYTHON_WITHOUT_ASSERTIONS
+ if (unlikely(!(((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_cur_scope->__pyx_v_self)->hg != NULL))) {
+ PyErr_SetNone(PyExc_AssertionError);
+ {__pyx_filename = __pyx_f[0]; __pyx_lineno = 138; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ }
+ #endif
+
+ /* "_cdec.pyx":139
+ * def sample(self, unsigned n):
+ * assert (self.hg != NULL)
+ * cdef vector[hypergraph.Hypothesis]* hypos = new vector[hypergraph.Hypothesis]() # <<<<<<<<<<<<<<
+ * if self.rng == NULL:
+ * self.rng = new MT19937()
+ */
+ __pyx_cur_scope->__pyx_v_hypos = new std::vector<HypergraphSampler::Hypothesis>();
+
+ /* "_cdec.pyx":140
+ * assert (self.hg != NULL)
+ * cdef vector[hypergraph.Hypothesis]* hypos = new vector[hypergraph.Hypothesis]()
+ * if self.rng == NULL: # <<<<<<<<<<<<<<
+ * self.rng = new MT19937()
+ * hypergraph.sample_hypotheses(self.hg[0], n, self.rng, hypos)
+ */
+ __pyx_t_1 = (((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_cur_scope->__pyx_v_self)->rng == NULL);
+ if (__pyx_t_1) {
+
+ /* "_cdec.pyx":141
+ * cdef vector[hypergraph.Hypothesis]* hypos = new vector[hypergraph.Hypothesis]()
+ * if self.rng == NULL:
+ * self.rng = new MT19937() # <<<<<<<<<<<<<<
+ * hypergraph.sample_hypotheses(self.hg[0], n, self.rng, hypos)
+ * cdef str sentence
+ */
+ ((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_cur_scope->__pyx_v_self)->rng = new MT19937();
+ goto __pyx_L4;
+ }
+ __pyx_L4:;
+
+ /* "_cdec.pyx":142
+ * if self.rng == NULL:
+ * self.rng = new MT19937()
+ * hypergraph.sample_hypotheses(self.hg[0], n, self.rng, hypos) # <<<<<<<<<<<<<<
+ * cdef str sentence
+ * cdef unsigned k
+ */
+ HypergraphSampler::sample_hypotheses((((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_cur_scope->__pyx_v_self)->hg[0]), __pyx_cur_scope->__pyx_v_n, ((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_cur_scope->__pyx_v_self)->rng, __pyx_cur_scope->__pyx_v_hypos);
+
+ /* "_cdec.pyx":145
+ * cdef str sentence
+ * cdef unsigned k
+ * for k in range(hypos.size()): # <<<<<<<<<<<<<<
+ * sentence = GetString(hypos[0][k].words).c_str()
+ * yield sentence.decode('utf8')
+ */
+ __pyx_t_2 = __pyx_cur_scope->__pyx_v_hypos->size();
+ for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) {
+ __pyx_cur_scope->__pyx_v_k = __pyx_t_3;
+
+ /* "_cdec.pyx":146
+ * cdef unsigned k
+ * for k in range(hypos.size()):
+ * sentence = GetString(hypos[0][k].words).c_str() # <<<<<<<<<<<<<<
+ * yield sentence.decode('utf8')
+ * del hypos
+ */
+ __pyx_t_4 = PyBytes_FromString(TD::GetString(((__pyx_cur_scope->__pyx_v_hypos[0])[__pyx_cur_scope->__pyx_v_k]).words).c_str()); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 146; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_4));
+ if (!(likely(PyString_CheckExact(((PyObject *)__pyx_t_4)))||(PyErr_Format(PyExc_TypeError, "Expected str, got %.200s", Py_TYPE(((PyObject *)__pyx_t_4))->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 146; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_XGOTREF(((PyObject *)__pyx_cur_scope->__pyx_v_sentence));
+ __Pyx_XDECREF(((PyObject *)__pyx_cur_scope->__pyx_v_sentence));
+ __Pyx_GIVEREF(((PyObject *)__pyx_t_4));
+ __pyx_cur_scope->__pyx_v_sentence = ((PyObject*)__pyx_t_4);
+ __pyx_t_4 = 0;
+
+ /* "_cdec.pyx":147
+ * for k in range(hypos.size()):
+ * sentence = GetString(hypos[0][k].words).c_str()
+ * yield sentence.decode('utf8') # <<<<<<<<<<<<<<
+ * del hypos
+ *
+ */
+ __pyx_t_4 = PyObject_GetAttr(((PyObject *)__pyx_cur_scope->__pyx_v_sentence), __pyx_n_s__decode); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 147; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_4);
+ __pyx_t_5 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_k_tuple_12), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 147; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_5);
+ __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+ __pyx_r = __pyx_t_5;
+ __pyx_t_5 = 0;
+ __pyx_cur_scope->__pyx_t_0 = __pyx_t_2;
+ __pyx_cur_scope->__pyx_t_1 = __pyx_t_3;
+ __Pyx_XGIVEREF(__pyx_r);
+ __Pyx_RefNannyFinishContext();
+ /* return from generator, yielding value */
+ __pyx_cur_scope->__pyx_base.resume_label = 1;
+ return __pyx_r;
+ __pyx_L7_resume_from_yield:;
+ __pyx_t_2 = __pyx_cur_scope->__pyx_t_0;
+ __pyx_t_3 = __pyx_cur_scope->__pyx_t_1;
+ if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 147; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ }
+
+ /* "_cdec.pyx":148
+ * sentence = GetString(hypos[0][k].words).c_str()
+ * yield sentence.decode('utf8')
+ * del hypos # <<<<<<<<<<<<<<
+ *
+ * # TODO: get feature expectations, get partition function ("inside" score)
+ */
+ delete __pyx_cur_scope->__pyx_v_hypos;
+ PyErr_SetNone(PyExc_StopIteration); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 137; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ goto __pyx_L0;
+ __pyx_L1_error:;
+ __Pyx_XDECREF(__pyx_t_4);
+ __Pyx_XDECREF(__pyx_t_5);
+ __Pyx_AddTraceback("sample", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_L0:;
+ __Pyx_XDECREF(__pyx_r);
+ __pyx_cur_scope->__pyx_base.resume_label = -1;
+ __Pyx_RefNannyFinishContext();
+ return NULL;
+}
+
+/* "_cdec.pyx":157
+ * cdef lattice.Lattice* lattice
+ *
+ * def __init__(self, tuple plf_tuple): # <<<<<<<<<<<<<<
+ * self.lattice = new lattice.Lattice()
+ * cdef bytes plf = str(plf_tuple)
+ */
+
+static int __pyx_pf_5_cdec_7Lattice___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static int __pyx_pf_5_cdec_7Lattice___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+ PyObject *__pyx_v_plf_tuple = 0;
+ PyObject *__pyx_v_plf = 0;
+ int __pyx_r;
+ __Pyx_RefNannyDeclarations
+ PyObject *__pyx_t_1 = NULL;
+ PyObject *__pyx_t_2 = NULL;
+ char *__pyx_t_3;
+ int __pyx_lineno = 0;
+ const char *__pyx_filename = NULL;
+ int __pyx_clineno = 0;
+ static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__plf_tuple,0};
+ __Pyx_RefNannySetupContext("__init__");
+ {
+ PyObject* values[1] = {0};
+ if (unlikely(__pyx_kwds)) {
+ Py_ssize_t kw_args;
+ switch (PyTuple_GET_SIZE(__pyx_args)) {
+ case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
+ case 0: break;
+ default: goto __pyx_L5_argtuple_error;
+ }
+ kw_args = PyDict_Size(__pyx_kwds);
+ switch (PyTuple_GET_SIZE(__pyx_args)) {
+ case 0:
+ values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__plf_tuple);
+ if (likely(values[0])) kw_args--;
+ else goto __pyx_L5_argtuple_error;
+ }
+ if (unlikely(kw_args > 0)) {
+ if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "__init__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 157; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ }
+ } else if (PyTuple_GET_SIZE(__pyx_args) != 1) {
+ goto __pyx_L5_argtuple_error;
+ } else {
+ values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
+ }
+ __pyx_v_plf_tuple = ((PyObject*)values[0]);
+ }
+ goto __pyx_L4_argument_unpacking_done;
+ __pyx_L5_argtuple_error:;
+ __Pyx_RaiseArgtupleInvalid("__init__", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 157; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+ __pyx_L3_error:;
+ __Pyx_AddTraceback("_cdec.Lattice.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __Pyx_RefNannyFinishContext();
+ return -1;
+ __pyx_L4_argument_unpacking_done:;
+ if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_plf_tuple), (&PyTuple_Type), 1, "plf_tuple", 1))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 157; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+
+ /* "_cdec.pyx":158
+ *
+ * def __init__(self, tuple plf_tuple):
+ * self.lattice = new lattice.Lattice() # <<<<<<<<<<<<<<
+ * cdef bytes plf = str(plf_tuple)
+ * hypergraph.PLFtoLattice(string(<char *>plf), self.lattice)
+ */
+ ((struct __pyx_obj_5_cdec_Lattice *)__pyx_v_self)->lattice = new Lattice();
+
+ /* "_cdec.pyx":159
+ * def __init__(self, tuple plf_tuple):
+ * self.lattice = new lattice.Lattice()
+ * cdef bytes plf = str(plf_tuple) # <<<<<<<<<<<<<<
+ * hypergraph.PLFtoLattice(string(<char *>plf), self.lattice)
+ *
+ */
+ __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 159; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_1));
+ __Pyx_INCREF(((PyObject *)__pyx_v_plf_tuple));
+ PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_v_plf_tuple));
+ __Pyx_GIVEREF(((PyObject *)__pyx_v_plf_tuple));
+ __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)(&PyString_Type))), ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 159; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
+ if (!(likely(PyBytes_CheckExact(__pyx_t_2))||((__pyx_t_2) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected bytes, got %.200s", Py_TYPE(__pyx_t_2)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 159; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_v_plf = ((PyObject*)__pyx_t_2);
+ __pyx_t_2 = 0;
+
+ /* "_cdec.pyx":160
+ * self.lattice = new lattice.Lattice()
+ * cdef bytes plf = str(plf_tuple)
+ * hypergraph.PLFtoLattice(string(<char *>plf), self.lattice) # <<<<<<<<<<<<<<
+ *
+ * def __str__(self):
+ */
+ __pyx_t_3 = PyBytes_AsString(((PyObject *)__pyx_v_plf)); if (unlikely((!__pyx_t_3) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 160; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ HypergraphIO::PLFtoLattice(std::string(((char *)__pyx_t_3)), ((struct __pyx_obj_5_cdec_Lattice *)__pyx_v_self)->lattice);
+
+ __pyx_r = 0;
+ goto __pyx_L0;
+ __pyx_L1_error:;
+ __Pyx_XDECREF(__pyx_t_1);
+ __Pyx_XDECREF(__pyx_t_2);
+ __Pyx_AddTraceback("_cdec.Lattice.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_r = -1;
+ __pyx_L0:;
+ __Pyx_XDECREF(__pyx_v_plf);
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* "_cdec.pyx":162
+ * hypergraph.PLFtoLattice(string(<char *>plf), self.lattice)
+ *
+ * def __str__(self): # <<<<<<<<<<<<<<
+ * return hypergraph.AsPLF(self.lattice[0]).c_str()
+ *
+ */
+
+static PyObject *__pyx_pf_5_cdec_7Lattice_1__str__(PyObject *__pyx_v_self); /*proto*/
+static PyObject *__pyx_pf_5_cdec_7Lattice_1__str__(PyObject *__pyx_v_self) {
+ PyObject *__pyx_r = NULL;
+ __Pyx_RefNannyDeclarations
+ PyObject *__pyx_t_1 = NULL;
+ int __pyx_lineno = 0;
+ const char *__pyx_filename = NULL;
+ int __pyx_clineno = 0;
+ __Pyx_RefNannySetupContext("__str__");
+
+ /* "_cdec.pyx":163
+ *
+ * def __str__(self):
+ * return hypergraph.AsPLF(self.lattice[0]).c_str() # <<<<<<<<<<<<<<
+ *
+ * def __iter__(self):
+ */
+ __Pyx_XDECREF(__pyx_r);
+ __pyx_t_1 = PyBytes_FromString(HypergraphIO::AsPLF((((struct __pyx_obj_5_cdec_Lattice *)__pyx_v_self)->lattice[0]), NULL).c_str()); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 163; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_1));
+ __pyx_r = ((PyObject *)__pyx_t_1);
+ __pyx_t_1 = 0;
+ goto __pyx_L0;
+
+ __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+ goto __pyx_L0;
+ __pyx_L1_error:;
+ __Pyx_XDECREF(__pyx_t_1);
+ __Pyx_AddTraceback("_cdec.Lattice.__str__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_r = NULL;
+ __pyx_L0:;
+ __Pyx_XGIVEREF(__pyx_r);
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* "_cdec.pyx":165
+ * return hypergraph.AsPLF(self.lattice[0]).c_str()
+ *
+ * def __iter__(self): # <<<<<<<<<<<<<<
+ * return iter(eval(str(self)))
+ *
+ */
+
+static PyObject *__pyx_pf_5_cdec_7Lattice_2__iter__(PyObject *__pyx_v_self); /*proto*/
+static PyObject *__pyx_pf_5_cdec_7Lattice_2__iter__(PyObject *__pyx_v_self) {
+ PyObject *__pyx_r = NULL;
+ __Pyx_RefNannyDeclarations
+ PyObject *__pyx_t_1 = NULL;
+ PyObject *__pyx_t_2 = NULL;
+ int __pyx_lineno = 0;
+ const char *__pyx_filename = NULL;
+ int __pyx_clineno = 0;
+ __Pyx_RefNannySetupContext("__iter__");
+
+ /* "_cdec.pyx":166
+ *
+ * def __iter__(self):
+ * return iter(eval(str(self))) # <<<<<<<<<<<<<<
+ *
+ * def __dealloc__(self):
+ */
+ __Pyx_XDECREF(__pyx_r);
+ __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 166; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_1));
+ __Pyx_INCREF(__pyx_v_self);
+ PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_self);
+ __Pyx_GIVEREF(__pyx_v_self);
+ __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)(&PyString_Type))), ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 166; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_DECREF(((PyObject *)__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 = 166; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_t_1));
+ PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_2);
+ __Pyx_GIVEREF(__pyx_t_2);
+ __pyx_t_2 = 0;
+ __pyx_t_2 = PyObject_Call(__pyx_builtin_eval, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 166; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
+ __pyx_t_1 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 166; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(__pyx_t_1);
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ __pyx_r = __pyx_t_1;
+ __pyx_t_1 = 0;
+ goto __pyx_L0;
+
+ __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+ goto __pyx_L0;
+ __pyx_L1_error:;
+ __Pyx_XDECREF(__pyx_t_1);
+ __Pyx_XDECREF(__pyx_t_2);
+ __Pyx_AddTraceback("_cdec.Lattice.__iter__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_r = NULL;
+ __pyx_L0:;
+ __Pyx_XGIVEREF(__pyx_r);
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* "_cdec.pyx":168
+ * return iter(eval(str(self)))
+ *
+ * def __dealloc__(self): # <<<<<<<<<<<<<<
+ * del self.lattice
+ *
+ */
+
+static void __pyx_pf_5_cdec_7Lattice_3__dealloc__(PyObject *__pyx_v_self); /*proto*/
+static void __pyx_pf_5_cdec_7Lattice_3__dealloc__(PyObject *__pyx_v_self) {
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("__dealloc__");
+
+ /* "_cdec.pyx":169
+ *
+ * def __dealloc__(self):
+ * del self.lattice # <<<<<<<<<<<<<<
+ *
+ * # TODO: wrap SparseVector
+ */
+ delete ((struct __pyx_obj_5_cdec_Lattice *)__pyx_v_self)->lattice;
+
+ __Pyx_RefNannyFinishContext();
+}
+
static PyObject *__pyx_tp_new_5_cdec_Weights(PyTypeObject *t, PyObject *a, PyObject *k) {
PyObject *o = (*t->tp_alloc)(t, 0);
if (!o) return 0;
@@ -2594,11 +3690,25 @@ static PyObject *__pyx_tp_new_5_cdec_Hypergraph(PyTypeObject *t, PyObject *a, Py
}
static void __pyx_tp_dealloc_5_cdec_Hypergraph(PyObject *o) {
+ {
+ PyObject *etype, *eval, *etb;
+ PyErr_Fetch(&etype, &eval, &etb);
+ ++Py_REFCNT(o);
+ __pyx_pf_5_cdec_10Hypergraph___dealloc__(o);
+ if (PyErr_Occurred()) PyErr_WriteUnraisable(o);
+ --Py_REFCNT(o);
+ PyErr_Restore(etype, eval, etb);
+ }
(*Py_TYPE(o)->tp_free)(o);
}
static PyMethodDef __pyx_methods_5_cdec_Hypergraph[] = {
- {__Pyx_NAMESTR("viterbi"), (PyCFunction)__pyx_pf_5_cdec_10Hypergraph_viterbi, METH_NOARGS, __Pyx_DOCSTR(0)},
+ {__Pyx_NAMESTR("viterbi"), (PyCFunction)__pyx_pf_5_cdec_10Hypergraph_1viterbi, METH_NOARGS, __Pyx_DOCSTR(0)},
+ {__Pyx_NAMESTR("viterbi_tree"), (PyCFunction)__pyx_pf_5_cdec_10Hypergraph_2viterbi_tree, METH_NOARGS, __Pyx_DOCSTR(0)},
+ {__Pyx_NAMESTR("kbest"), (PyCFunction)__pyx_pf_5_cdec_10Hypergraph_3kbest, METH_O, __Pyx_DOCSTR(0)},
+ {__Pyx_NAMESTR("kbest_tree"), (PyCFunction)__pyx_pf_5_cdec_10Hypergraph_5kbest_tree, METH_O, __Pyx_DOCSTR(0)},
+ {__Pyx_NAMESTR("intersect"), (PyCFunction)__pyx_pf_5_cdec_10Hypergraph_7intersect, METH_O, __Pyx_DOCSTR(0)},
+ {__Pyx_NAMESTR("sample"), (PyCFunction)__pyx_pf_5_cdec_10Hypergraph_8sample, METH_O, __Pyx_DOCSTR(0)},
{0, 0, 0, 0}
};
@@ -2756,6 +3866,183 @@ static PyTypeObject __pyx_type_5_cdec_Hypergraph = {
#endif
};
+static PyObject *__pyx_tp_new_5_cdec_Lattice(PyTypeObject *t, PyObject *a, PyObject *k) {
+ PyObject *o = (*t->tp_alloc)(t, 0);
+ if (!o) return 0;
+ return o;
+}
+
+static void __pyx_tp_dealloc_5_cdec_Lattice(PyObject *o) {
+ {
+ PyObject *etype, *eval, *etb;
+ PyErr_Fetch(&etype, &eval, &etb);
+ ++Py_REFCNT(o);
+ __pyx_pf_5_cdec_7Lattice_3__dealloc__(o);
+ if (PyErr_Occurred()) PyErr_WriteUnraisable(o);
+ --Py_REFCNT(o);
+ PyErr_Restore(etype, eval, etb);
+ }
+ (*Py_TYPE(o)->tp_free)(o);
+}
+
+static PyMethodDef __pyx_methods_5_cdec_Lattice[] = {
+ {0, 0, 0, 0}
+};
+
+static PyNumberMethods __pyx_tp_as_number_Lattice = {
+ 0, /*nb_add*/
+ 0, /*nb_subtract*/
+ 0, /*nb_multiply*/
+ #if PY_MAJOR_VERSION < 3
+ 0, /*nb_divide*/
+ #endif
+ 0, /*nb_remainder*/
+ 0, /*nb_divmod*/
+ 0, /*nb_power*/
+ 0, /*nb_negative*/
+ 0, /*nb_positive*/
+ 0, /*nb_absolute*/
+ 0, /*nb_nonzero*/
+ 0, /*nb_invert*/
+ 0, /*nb_lshift*/
+ 0, /*nb_rshift*/
+ 0, /*nb_and*/
+ 0, /*nb_xor*/
+ 0, /*nb_or*/
+ #if PY_MAJOR_VERSION < 3
+ 0, /*nb_coerce*/
+ #endif
+ 0, /*nb_int*/
+ #if PY_MAJOR_VERSION < 3
+ 0, /*nb_long*/
+ #else
+ 0, /*reserved*/
+ #endif
+ 0, /*nb_float*/
+ #if PY_MAJOR_VERSION < 3
+ 0, /*nb_oct*/
+ #endif
+ #if PY_MAJOR_VERSION < 3
+ 0, /*nb_hex*/
+ #endif
+ 0, /*nb_inplace_add*/
+ 0, /*nb_inplace_subtract*/
+ 0, /*nb_inplace_multiply*/
+ #if PY_MAJOR_VERSION < 3
+ 0, /*nb_inplace_divide*/
+ #endif
+ 0, /*nb_inplace_remainder*/
+ 0, /*nb_inplace_power*/
+ 0, /*nb_inplace_lshift*/
+ 0, /*nb_inplace_rshift*/
+ 0, /*nb_inplace_and*/
+ 0, /*nb_inplace_xor*/
+ 0, /*nb_inplace_or*/
+ 0, /*nb_floor_divide*/
+ 0, /*nb_true_divide*/
+ 0, /*nb_inplace_floor_divide*/
+ 0, /*nb_inplace_true_divide*/
+ #if PY_VERSION_HEX >= 0x02050000
+ 0, /*nb_index*/
+ #endif
+};
+
+static PySequenceMethods __pyx_tp_as_sequence_Lattice = {
+ 0, /*sq_length*/
+ 0, /*sq_concat*/
+ 0, /*sq_repeat*/
+ 0, /*sq_item*/
+ 0, /*sq_slice*/
+ 0, /*sq_ass_item*/
+ 0, /*sq_ass_slice*/
+ 0, /*sq_contains*/
+ 0, /*sq_inplace_concat*/
+ 0, /*sq_inplace_repeat*/
+};
+
+static PyMappingMethods __pyx_tp_as_mapping_Lattice = {
+ 0, /*mp_length*/
+ 0, /*mp_subscript*/
+ 0, /*mp_ass_subscript*/
+};
+
+static PyBufferProcs __pyx_tp_as_buffer_Lattice = {
+ #if PY_MAJOR_VERSION < 3
+ 0, /*bf_getreadbuffer*/
+ #endif
+ #if PY_MAJOR_VERSION < 3
+ 0, /*bf_getwritebuffer*/
+ #endif
+ #if PY_MAJOR_VERSION < 3
+ 0, /*bf_getsegcount*/
+ #endif
+ #if PY_MAJOR_VERSION < 3
+ 0, /*bf_getcharbuffer*/
+ #endif
+ #if PY_VERSION_HEX >= 0x02060000
+ 0, /*bf_getbuffer*/
+ #endif
+ #if PY_VERSION_HEX >= 0x02060000
+ 0, /*bf_releasebuffer*/
+ #endif
+};
+
+static PyTypeObject __pyx_type_5_cdec_Lattice = {
+ PyVarObject_HEAD_INIT(0, 0)
+ __Pyx_NAMESTR("_cdec.Lattice"), /*tp_name*/
+ sizeof(struct __pyx_obj_5_cdec_Lattice), /*tp_basicsize*/
+ 0, /*tp_itemsize*/
+ __pyx_tp_dealloc_5_cdec_Lattice, /*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*/
+ &__pyx_tp_as_number_Lattice, /*tp_as_number*/
+ &__pyx_tp_as_sequence_Lattice, /*tp_as_sequence*/
+ &__pyx_tp_as_mapping_Lattice, /*tp_as_mapping*/
+ 0, /*tp_hash*/
+ 0, /*tp_call*/
+ __pyx_pf_5_cdec_7Lattice_1__str__, /*tp_str*/
+ 0, /*tp_getattro*/
+ 0, /*tp_setattro*/
+ &__pyx_tp_as_buffer_Lattice, /*tp_as_buffer*/
+ Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE, /*tp_flags*/
+ 0, /*tp_doc*/
+ 0, /*tp_traverse*/
+ 0, /*tp_clear*/
+ 0, /*tp_richcompare*/
+ 0, /*tp_weaklistoffset*/
+ __pyx_pf_5_cdec_7Lattice_2__iter__, /*tp_iter*/
+ 0, /*tp_iternext*/
+ __pyx_methods_5_cdec_Lattice, /*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*/
+ __pyx_pf_5_cdec_7Lattice___init__, /*tp_init*/
+ 0, /*tp_alloc*/
+ __pyx_tp_new_5_cdec_Lattice, /*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_5_cdec___pyx_Generator(PyTypeObject *t, PyObject *a, PyObject *k) {
struct __pyx_Generator_object *p;
PyObject *o = (*t->tp_alloc)(t, 0);
@@ -3159,6 +4446,625 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct____iter__ = {
#endif
};
+static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_1_kbest(PyTypeObject *t, PyObject *a, PyObject *k) {
+ struct __pyx_obj_5_cdec___pyx_scope_struct_1_kbest *p;
+ PyObject *o = __pyx_tp_new_5_cdec___pyx_Generator(t, a, k);
+ if (!o) return 0;
+ p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_1_kbest *)o);
+ p->__pyx_v_self = 0;
+ p->__pyx_v_size = 0;
+ p->__pyx_v_tree = 0;
+ return o;
+}
+
+static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_1_kbest(PyObject *o) {
+ struct __pyx_obj_5_cdec___pyx_scope_struct_1_kbest *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_1_kbest *)o;
+ Py_XDECREF(((PyObject *)p->__pyx_v_self));
+ Py_XDECREF(p->__pyx_v_size);
+ Py_XDECREF(((PyObject *)p->__pyx_v_tree));
+ __pyx_tp_dealloc_5_cdec___pyx_Generator(o);
+}
+
+static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_1_kbest(PyObject *o, visitproc v, void *a) {
+ int e;
+ struct __pyx_obj_5_cdec___pyx_scope_struct_1_kbest *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_1_kbest *)o;
+ e = __pyx_tp_traverse_5_cdec___pyx_Generator(o, v, a); if (e) return e;
+ if (p->__pyx_v_self) {
+ e = (*v)(((PyObject*)p->__pyx_v_self), a); if (e) return e;
+ }
+ if (p->__pyx_v_size) {
+ e = (*v)(p->__pyx_v_size, a); if (e) return e;
+ }
+ if (p->__pyx_v_tree) {
+ e = (*v)(p->__pyx_v_tree, a); if (e) return e;
+ }
+ return 0;
+}
+
+static int __pyx_tp_clear_5_cdec___pyx_scope_struct_1_kbest(PyObject *o) {
+ struct __pyx_obj_5_cdec___pyx_scope_struct_1_kbest *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_1_kbest *)o;
+ PyObject* tmp;
+ __pyx_tp_clear_5_cdec___pyx_Generator(o);
+ tmp = ((PyObject*)p->__pyx_v_self);
+ p->__pyx_v_self = Py_None; Py_INCREF(Py_None);
+ Py_XDECREF(tmp);
+ tmp = ((PyObject*)p->__pyx_v_size);
+ p->__pyx_v_size = Py_None; Py_INCREF(Py_None);
+ Py_XDECREF(tmp);
+ tmp = ((PyObject*)p->__pyx_v_tree);
+ p->__pyx_v_tree = ((PyObject*)Py_None); Py_INCREF(Py_None);
+ Py_XDECREF(tmp);
+ return 0;
+}
+
+static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_1_kbest[] = {
+ {0, 0, 0, 0}
+};
+
+static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_1_kbest = {
+ 0, /*nb_add*/
+ 0, /*nb_subtract*/
+ 0, /*nb_multiply*/
+ #if PY_MAJOR_VERSION < 3
+ 0, /*nb_divide*/
+ #endif
+ 0, /*nb_remainder*/
+ 0, /*nb_divmod*/
+ 0, /*nb_power*/
+ 0, /*nb_negative*/
+ 0, /*nb_positive*/
+ 0, /*nb_absolute*/
+ 0, /*nb_nonzero*/
+ 0, /*nb_invert*/
+ 0, /*nb_lshift*/
+ 0, /*nb_rshift*/
+ 0, /*nb_and*/
+ 0, /*nb_xor*/
+ 0, /*nb_or*/
+ #if PY_MAJOR_VERSION < 3
+ 0, /*nb_coerce*/
+ #endif
+ 0, /*nb_int*/
+ #if PY_MAJOR_VERSION < 3
+ 0, /*nb_long*/
+ #else
+ 0, /*reserved*/
+ #endif
+ 0, /*nb_float*/
+ #if PY_MAJOR_VERSION < 3
+ 0, /*nb_oct*/
+ #endif
+ #if PY_MAJOR_VERSION < 3
+ 0, /*nb_hex*/
+ #endif
+ 0, /*nb_inplace_add*/
+ 0, /*nb_inplace_subtract*/
+ 0, /*nb_inplace_multiply*/
+ #if PY_MAJOR_VERSION < 3
+ 0, /*nb_inplace_divide*/
+ #endif
+ 0, /*nb_inplace_remainder*/
+ 0, /*nb_inplace_power*/
+ 0, /*nb_inplace_lshift*/
+ 0, /*nb_inplace_rshift*/
+ 0, /*nb_inplace_and*/
+ 0, /*nb_inplace_xor*/
+ 0, /*nb_inplace_or*/
+ 0, /*nb_floor_divide*/
+ 0, /*nb_true_divide*/
+ 0, /*nb_inplace_floor_divide*/
+ 0, /*nb_inplace_true_divide*/
+ #if PY_VERSION_HEX >= 0x02050000
+ 0, /*nb_index*/
+ #endif
+};
+
+static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_1_kbest = {
+ 0, /*sq_length*/
+ 0, /*sq_concat*/
+ 0, /*sq_repeat*/
+ 0, /*sq_item*/
+ 0, /*sq_slice*/
+ 0, /*sq_ass_item*/
+ 0, /*sq_ass_slice*/
+ 0, /*sq_contains*/
+ 0, /*sq_inplace_concat*/
+ 0, /*sq_inplace_repeat*/
+};
+
+static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_1_kbest = {
+ 0, /*mp_length*/
+ 0, /*mp_subscript*/
+ 0, /*mp_ass_subscript*/
+};
+
+static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_1_kbest = {
+ #if PY_MAJOR_VERSION < 3
+ 0, /*bf_getreadbuffer*/
+ #endif
+ #if PY_MAJOR_VERSION < 3
+ 0, /*bf_getwritebuffer*/
+ #endif
+ #if PY_MAJOR_VERSION < 3
+ 0, /*bf_getsegcount*/
+ #endif
+ #if PY_MAJOR_VERSION < 3
+ 0, /*bf_getcharbuffer*/
+ #endif
+ #if PY_VERSION_HEX >= 0x02060000
+ 0, /*bf_getbuffer*/
+ #endif
+ #if PY_VERSION_HEX >= 0x02060000
+ 0, /*bf_releasebuffer*/
+ #endif
+};
+
+static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_1_kbest = {
+ PyVarObject_HEAD_INIT(0, 0)
+ __Pyx_NAMESTR("_cdec.__pyx_scope_struct_1_kbest"), /*tp_name*/
+ sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_1_kbest), /*tp_basicsize*/
+ 0, /*tp_itemsize*/
+ __pyx_tp_dealloc_5_cdec___pyx_scope_struct_1_kbest, /*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*/
+ &__pyx_tp_as_number___pyx_scope_struct_1_kbest, /*tp_as_number*/
+ &__pyx_tp_as_sequence___pyx_scope_struct_1_kbest, /*tp_as_sequence*/
+ &__pyx_tp_as_mapping___pyx_scope_struct_1_kbest, /*tp_as_mapping*/
+ 0, /*tp_hash*/
+ 0, /*tp_call*/
+ 0, /*tp_str*/
+ 0, /*tp_getattro*/
+ 0, /*tp_setattro*/
+ &__pyx_tp_as_buffer___pyx_scope_struct_1_kbest, /*tp_as_buffer*/
+ Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
+ 0, /*tp_doc*/
+ __pyx_tp_traverse_5_cdec___pyx_scope_struct_1_kbest, /*tp_traverse*/
+ __pyx_tp_clear_5_cdec___pyx_scope_struct_1_kbest, /*tp_clear*/
+ 0, /*tp_richcompare*/
+ 0, /*tp_weaklistoffset*/
+ 0, /*tp_iter*/
+ 0, /*tp_iternext*/
+ __pyx_methods_5_cdec___pyx_scope_struct_1_kbest, /*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_5_cdec___pyx_scope_struct_1_kbest, /*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_5_cdec___pyx_scope_struct_2_kbest_tree(PyTypeObject *t, PyObject *a, PyObject *k) {
+ struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest_tree *p;
+ PyObject *o = __pyx_tp_new_5_cdec___pyx_Generator(t, a, k);
+ if (!o) return 0;
+ p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest_tree *)o);
+ p->__pyx_v_self = 0;
+ p->__pyx_v_sentence = 0;
+ p->__pyx_v_size = 0;
+ return o;
+}
+
+static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_2_kbest_tree(PyObject *o) {
+ struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest_tree *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest_tree *)o;
+ Py_XDECREF(((PyObject *)p->__pyx_v_self));
+ Py_XDECREF(((PyObject *)p->__pyx_v_sentence));
+ Py_XDECREF(p->__pyx_v_size);
+ __pyx_tp_dealloc_5_cdec___pyx_Generator(o);
+}
+
+static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_2_kbest_tree(PyObject *o, visitproc v, void *a) {
+ int e;
+ struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest_tree *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest_tree *)o;
+ e = __pyx_tp_traverse_5_cdec___pyx_Generator(o, v, a); if (e) return e;
+ 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_size) {
+ e = (*v)(p->__pyx_v_size, a); if (e) return e;
+ }
+ return 0;
+}
+
+static int __pyx_tp_clear_5_cdec___pyx_scope_struct_2_kbest_tree(PyObject *o) {
+ struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest_tree *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest_tree *)o;
+ PyObject* tmp;
+ __pyx_tp_clear_5_cdec___pyx_Generator(o);
+ tmp = ((PyObject*)p->__pyx_v_self);
+ p->__pyx_v_self = Py_None; Py_INCREF(Py_None);
+ Py_XDECREF(tmp);
+ tmp = ((PyObject*)p->__pyx_v_sentence);
+ p->__pyx_v_sentence = ((PyObject*)Py_None); Py_INCREF(Py_None);
+ Py_XDECREF(tmp);
+ tmp = ((PyObject*)p->__pyx_v_size);
+ p->__pyx_v_size = Py_None; Py_INCREF(Py_None);
+ Py_XDECREF(tmp);
+ return 0;
+}
+
+static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_2_kbest_tree[] = {
+ {0, 0, 0, 0}
+};
+
+static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_2_kbest_tree = {
+ 0, /*nb_add*/
+ 0, /*nb_subtract*/
+ 0, /*nb_multiply*/
+ #if PY_MAJOR_VERSION < 3
+ 0, /*nb_divide*/
+ #endif
+ 0, /*nb_remainder*/
+ 0, /*nb_divmod*/
+ 0, /*nb_power*/
+ 0, /*nb_negative*/
+ 0, /*nb_positive*/
+ 0, /*nb_absolute*/
+ 0, /*nb_nonzero*/
+ 0, /*nb_invert*/
+ 0, /*nb_lshift*/
+ 0, /*nb_rshift*/
+ 0, /*nb_and*/
+ 0, /*nb_xor*/
+ 0, /*nb_or*/
+ #if PY_MAJOR_VERSION < 3
+ 0, /*nb_coerce*/
+ #endif
+ 0, /*nb_int*/
+ #if PY_MAJOR_VERSION < 3
+ 0, /*nb_long*/
+ #else
+ 0, /*reserved*/
+ #endif
+ 0, /*nb_float*/
+ #if PY_MAJOR_VERSION < 3
+ 0, /*nb_oct*/
+ #endif
+ #if PY_MAJOR_VERSION < 3
+ 0, /*nb_hex*/
+ #endif
+ 0, /*nb_inplace_add*/
+ 0, /*nb_inplace_subtract*/
+ 0, /*nb_inplace_multiply*/
+ #if PY_MAJOR_VERSION < 3
+ 0, /*nb_inplace_divide*/
+ #endif
+ 0, /*nb_inplace_remainder*/
+ 0, /*nb_inplace_power*/
+ 0, /*nb_inplace_lshift*/
+ 0, /*nb_inplace_rshift*/
+ 0, /*nb_inplace_and*/
+ 0, /*nb_inplace_xor*/
+ 0, /*nb_inplace_or*/
+ 0, /*nb_floor_divide*/
+ 0, /*nb_true_divide*/
+ 0, /*nb_inplace_floor_divide*/
+ 0, /*nb_inplace_true_divide*/
+ #if PY_VERSION_HEX >= 0x02050000
+ 0, /*nb_index*/
+ #endif
+};
+
+static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_2_kbest_tree = {
+ 0, /*sq_length*/
+ 0, /*sq_concat*/
+ 0, /*sq_repeat*/
+ 0, /*sq_item*/
+ 0, /*sq_slice*/
+ 0, /*sq_ass_item*/
+ 0, /*sq_ass_slice*/
+ 0, /*sq_contains*/
+ 0, /*sq_inplace_concat*/
+ 0, /*sq_inplace_repeat*/
+};
+
+static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_2_kbest_tree = {
+ 0, /*mp_length*/
+ 0, /*mp_subscript*/
+ 0, /*mp_ass_subscript*/
+};
+
+static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_2_kbest_tree = {
+ #if PY_MAJOR_VERSION < 3
+ 0, /*bf_getreadbuffer*/
+ #endif
+ #if PY_MAJOR_VERSION < 3
+ 0, /*bf_getwritebuffer*/
+ #endif
+ #if PY_MAJOR_VERSION < 3
+ 0, /*bf_getsegcount*/
+ #endif
+ #if PY_MAJOR_VERSION < 3
+ 0, /*bf_getcharbuffer*/
+ #endif
+ #if PY_VERSION_HEX >= 0x02060000
+ 0, /*bf_getbuffer*/
+ #endif
+ #if PY_VERSION_HEX >= 0x02060000
+ 0, /*bf_releasebuffer*/
+ #endif
+};
+
+static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_2_kbest_tree = {
+ PyVarObject_HEAD_INIT(0, 0)
+ __Pyx_NAMESTR("_cdec.__pyx_scope_struct_2_kbest_tree"), /*tp_name*/
+ sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest_tree), /*tp_basicsize*/
+ 0, /*tp_itemsize*/
+ __pyx_tp_dealloc_5_cdec___pyx_scope_struct_2_kbest_tree, /*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*/
+ &__pyx_tp_as_number___pyx_scope_struct_2_kbest_tree, /*tp_as_number*/
+ &__pyx_tp_as_sequence___pyx_scope_struct_2_kbest_tree, /*tp_as_sequence*/
+ &__pyx_tp_as_mapping___pyx_scope_struct_2_kbest_tree, /*tp_as_mapping*/
+ 0, /*tp_hash*/
+ 0, /*tp_call*/
+ 0, /*tp_str*/
+ 0, /*tp_getattro*/
+ 0, /*tp_setattro*/
+ &__pyx_tp_as_buffer___pyx_scope_struct_2_kbest_tree, /*tp_as_buffer*/
+ Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
+ 0, /*tp_doc*/
+ __pyx_tp_traverse_5_cdec___pyx_scope_struct_2_kbest_tree, /*tp_traverse*/
+ __pyx_tp_clear_5_cdec___pyx_scope_struct_2_kbest_tree, /*tp_clear*/
+ 0, /*tp_richcompare*/
+ 0, /*tp_weaklistoffset*/
+ 0, /*tp_iter*/
+ 0, /*tp_iternext*/
+ __pyx_methods_5_cdec___pyx_scope_struct_2_kbest_tree, /*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_5_cdec___pyx_scope_struct_2_kbest_tree, /*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_5_cdec___pyx_scope_struct_3_sample(PyTypeObject *t, PyObject *a, PyObject *k) {
+ struct __pyx_obj_5_cdec___pyx_scope_struct_3_sample *p;
+ PyObject *o = __pyx_tp_new_5_cdec___pyx_Generator(t, a, k);
+ if (!o) return 0;
+ p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_3_sample *)o);
+ p->__pyx_v_self = 0;
+ p->__pyx_v_sentence = 0;
+ return o;
+}
+
+static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_3_sample(PyObject *o) {
+ struct __pyx_obj_5_cdec___pyx_scope_struct_3_sample *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_3_sample *)o;
+ Py_XDECREF(((PyObject *)p->__pyx_v_self));
+ Py_XDECREF(((PyObject *)p->__pyx_v_sentence));
+ __pyx_tp_dealloc_5_cdec___pyx_Generator(o);
+}
+
+static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_3_sample(PyObject *o, visitproc v, void *a) {
+ int e;
+ struct __pyx_obj_5_cdec___pyx_scope_struct_3_sample *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_3_sample *)o;
+ e = __pyx_tp_traverse_5_cdec___pyx_Generator(o, v, a); if (e) return e;
+ 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;
+ }
+ return 0;
+}
+
+static int __pyx_tp_clear_5_cdec___pyx_scope_struct_3_sample(PyObject *o) {
+ struct __pyx_obj_5_cdec___pyx_scope_struct_3_sample *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_3_sample *)o;
+ PyObject* tmp;
+ __pyx_tp_clear_5_cdec___pyx_Generator(o);
+ tmp = ((PyObject*)p->__pyx_v_self);
+ p->__pyx_v_self = Py_None; Py_INCREF(Py_None);
+ Py_XDECREF(tmp);
+ tmp = ((PyObject*)p->__pyx_v_sentence);
+ p->__pyx_v_sentence = ((PyObject*)Py_None); Py_INCREF(Py_None);
+ Py_XDECREF(tmp);
+ return 0;
+}
+
+static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_3_sample[] = {
+ {0, 0, 0, 0}
+};
+
+static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_3_sample = {
+ 0, /*nb_add*/
+ 0, /*nb_subtract*/
+ 0, /*nb_multiply*/
+ #if PY_MAJOR_VERSION < 3
+ 0, /*nb_divide*/
+ #endif
+ 0, /*nb_remainder*/
+ 0, /*nb_divmod*/
+ 0, /*nb_power*/
+ 0, /*nb_negative*/
+ 0, /*nb_positive*/
+ 0, /*nb_absolute*/
+ 0, /*nb_nonzero*/
+ 0, /*nb_invert*/
+ 0, /*nb_lshift*/
+ 0, /*nb_rshift*/
+ 0, /*nb_and*/
+ 0, /*nb_xor*/
+ 0, /*nb_or*/
+ #if PY_MAJOR_VERSION < 3
+ 0, /*nb_coerce*/
+ #endif
+ 0, /*nb_int*/
+ #if PY_MAJOR_VERSION < 3
+ 0, /*nb_long*/
+ #else
+ 0, /*reserved*/
+ #endif
+ 0, /*nb_float*/
+ #if PY_MAJOR_VERSION < 3
+ 0, /*nb_oct*/
+ #endif
+ #if PY_MAJOR_VERSION < 3
+ 0, /*nb_hex*/
+ #endif
+ 0, /*nb_inplace_add*/
+ 0, /*nb_inplace_subtract*/
+ 0, /*nb_inplace_multiply*/
+ #if PY_MAJOR_VERSION < 3
+ 0, /*nb_inplace_divide*/
+ #endif
+ 0, /*nb_inplace_remainder*/
+ 0, /*nb_inplace_power*/
+ 0, /*nb_inplace_lshift*/
+ 0, /*nb_inplace_rshift*/
+ 0, /*nb_inplace_and*/
+ 0, /*nb_inplace_xor*/
+ 0, /*nb_inplace_or*/
+ 0, /*nb_floor_divide*/
+ 0, /*nb_true_divide*/
+ 0, /*nb_inplace_floor_divide*/
+ 0, /*nb_inplace_true_divide*/
+ #if PY_VERSION_HEX >= 0x02050000
+ 0, /*nb_index*/
+ #endif
+};
+
+static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_3_sample = {
+ 0, /*sq_length*/
+ 0, /*sq_concat*/
+ 0, /*sq_repeat*/
+ 0, /*sq_item*/
+ 0, /*sq_slice*/
+ 0, /*sq_ass_item*/
+ 0, /*sq_ass_slice*/
+ 0, /*sq_contains*/
+ 0, /*sq_inplace_concat*/
+ 0, /*sq_inplace_repeat*/
+};
+
+static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_3_sample = {
+ 0, /*mp_length*/
+ 0, /*mp_subscript*/
+ 0, /*mp_ass_subscript*/
+};
+
+static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_3_sample = {
+ #if PY_MAJOR_VERSION < 3
+ 0, /*bf_getreadbuffer*/
+ #endif
+ #if PY_MAJOR_VERSION < 3
+ 0, /*bf_getwritebuffer*/
+ #endif
+ #if PY_MAJOR_VERSION < 3
+ 0, /*bf_getsegcount*/
+ #endif
+ #if PY_MAJOR_VERSION < 3
+ 0, /*bf_getcharbuffer*/
+ #endif
+ #if PY_VERSION_HEX >= 0x02060000
+ 0, /*bf_getbuffer*/
+ #endif
+ #if PY_VERSION_HEX >= 0x02060000
+ 0, /*bf_releasebuffer*/
+ #endif
+};
+
+static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_3_sample = {
+ PyVarObject_HEAD_INIT(0, 0)
+ __Pyx_NAMESTR("_cdec.__pyx_scope_struct_3_sample"), /*tp_name*/
+ sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_3_sample), /*tp_basicsize*/
+ 0, /*tp_itemsize*/
+ __pyx_tp_dealloc_5_cdec___pyx_scope_struct_3_sample, /*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*/
+ &__pyx_tp_as_number___pyx_scope_struct_3_sample, /*tp_as_number*/
+ &__pyx_tp_as_sequence___pyx_scope_struct_3_sample, /*tp_as_sequence*/
+ &__pyx_tp_as_mapping___pyx_scope_struct_3_sample, /*tp_as_mapping*/
+ 0, /*tp_hash*/
+ 0, /*tp_call*/
+ 0, /*tp_str*/
+ 0, /*tp_getattro*/
+ 0, /*tp_setattro*/
+ &__pyx_tp_as_buffer___pyx_scope_struct_3_sample, /*tp_as_buffer*/
+ Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
+ 0, /*tp_doc*/
+ __pyx_tp_traverse_5_cdec___pyx_scope_struct_3_sample, /*tp_traverse*/
+ __pyx_tp_clear_5_cdec___pyx_scope_struct_3_sample, /*tp_clear*/
+ 0, /*tp_richcompare*/
+ 0, /*tp_weaklistoffset*/
+ 0, /*tp_iter*/
+ 0, /*tp_iternext*/
+ __pyx_methods_5_cdec___pyx_scope_struct_3_sample, /*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_5_cdec___pyx_scope_struct_3_sample, /*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}
};
@@ -3192,9 +5098,11 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = {
{&__pyx_n_s__decode, __pyx_k__decode, sizeof(__pyx_k__decode), 0, 0, 1, 1},
{&__pyx_n_s__decoder, __pyx_k__decoder, sizeof(__pyx_k__decoder), 0, 0, 1, 1},
{&__pyx_n_s__encode, __pyx_k__encode, sizeof(__pyx_k__encode), 0, 0, 1, 1},
+ {&__pyx_n_s__eval, __pyx_k__eval, sizeof(__pyx_k__eval), 0, 0, 1, 1},
{&__pyx_n_s__fromconfig, __pyx_k__fromconfig, sizeof(__pyx_k__fromconfig), 0, 0, 1, 1},
{&__pyx_n_s__grammar, __pyx_k__grammar, sizeof(__pyx_k__grammar), 0, 0, 1, 1},
{&__pyx_n_s__open, __pyx_k__open, sizeof(__pyx_k__open), 0, 0, 1, 1},
+ {&__pyx_n_s__plf_tuple, __pyx_k__plf_tuple, sizeof(__pyx_k__plf_tuple), 0, 0, 1, 1},
{&__pyx_n_s__range, __pyx_k__range, sizeof(__pyx_k__range), 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},
@@ -3204,10 +5112,11 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = {
{0, 0, 0, 0, 0, 0, 0}
};
static int __Pyx_InitCachedBuiltins(void) {
- __pyx_builtin_Exception = __Pyx_GetName(__pyx_b, __pyx_n_s__Exception); if (!__pyx_builtin_Exception) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __pyx_builtin_KeyError = __Pyx_GetName(__pyx_b, __pyx_n_s__KeyError); if (!__pyx_builtin_KeyError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 22; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __pyx_builtin_range = __Pyx_GetName(__pyx_b, __pyx_n_s__range); if (!__pyx_builtin_range) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- __pyx_builtin_open = __Pyx_GetName(__pyx_b, __pyx_n_s__open); if (!__pyx_builtin_open) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_builtin_Exception = __Pyx_GetName(__pyx_b, __pyx_n_s__Exception); if (!__pyx_builtin_Exception) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 12; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_builtin_KeyError = __Pyx_GetName(__pyx_b, __pyx_n_s__KeyError); if (!__pyx_builtin_KeyError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 25; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_builtin_range = __Pyx_GetName(__pyx_b, __pyx_n_s__range); if (!__pyx_builtin_range) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 35; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_builtin_open = __Pyx_GetName(__pyx_b, __pyx_n_s__open); if (!__pyx_builtin_open) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_builtin_eval = __Pyx_GetName(__pyx_b, __pyx_n_s__eval); if (!__pyx_builtin_eval) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 166; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
return 0;
__pyx_L1_error:;
return -1;
@@ -3217,42 +5126,42 @@ static int __Pyx_InitCachedConstants(void) {
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("__Pyx_InitCachedConstants");
- /* "_cdec.pyx":58
+ /* "_cdec.pyx":61
* for line in fp:
* line = line.strip()
* if not line or line.startswith('#'): continue # <<<<<<<<<<<<<<
* param, value = line.split('=')
* config[param.strip()] = value.strip()
*/
- __pyx_k_tuple_2 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_k_tuple_2 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(((PyObject *)__pyx_k_tuple_2));
__Pyx_INCREF(((PyObject *)__pyx_kp_s_1));
PyTuple_SET_ITEM(__pyx_k_tuple_2, 0, ((PyObject *)__pyx_kp_s_1));
__Pyx_GIVEREF(((PyObject *)__pyx_kp_s_1));
__Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_2));
- /* "_cdec.pyx":59
+ /* "_cdec.pyx":62
* line = line.strip()
* if not line or line.startswith('#'): continue
* param, value = line.split('=') # <<<<<<<<<<<<<<
* config[param.strip()] = value.strip()
* return cls(**config)
*/
- __pyx_k_tuple_4 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_k_tuple_4 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(((PyObject *)__pyx_k_tuple_4));
__Pyx_INCREF(((PyObject *)__pyx_kp_s_3));
PyTuple_SET_ITEM(__pyx_k_tuple_4, 0, ((PyObject *)__pyx_kp_s_3));
__Pyx_GIVEREF(((PyObject *)__pyx_kp_s_3));
__Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_4));
- /* "_cdec.pyx":55
+ /* "_cdec.pyx":58
* def fromconfig(cls, ini):
* cdef dict config = {}
* with open(ini) as fp: # <<<<<<<<<<<<<<
* for line in fp:
* line = line.strip()
*/
- __pyx_k_tuple_5 = PyTuple_New(3); if (unlikely(!__pyx_k_tuple_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_k_tuple_5 = PyTuple_New(3); if (unlikely(!__pyx_k_tuple_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(((PyObject *)__pyx_k_tuple_5));
__Pyx_INCREF(Py_None);
PyTuple_SET_ITEM(__pyx_k_tuple_5, 0, Py_None);
@@ -3265,14 +5174,14 @@ static int __Pyx_InitCachedConstants(void) {
__Pyx_GIVEREF(Py_None);
__Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_5));
- /* "_cdec.pyx":64
+ /* "_cdec.pyx":67
*
* def read_weights(self, cfg):
* with open(cfg) as fp: # <<<<<<<<<<<<<<
* for line in fp:
* fname, value = line.split()
*/
- __pyx_k_tuple_6 = PyTuple_New(3); if (unlikely(!__pyx_k_tuple_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_k_tuple_6 = PyTuple_New(3); if (unlikely(!__pyx_k_tuple_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(((PyObject *)__pyx_k_tuple_6));
__Pyx_INCREF(Py_None);
PyTuple_SET_ITEM(__pyx_k_tuple_6, 0, Py_None);
@@ -3285,33 +5194,89 @@ static int __Pyx_InitCachedConstants(void) {
__Pyx_GIVEREF(Py_None);
__Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_6));
- /* "_cdec.pyx":73
+ /* "_cdec.pyx":77
* self.dec.SetSentenceGrammarFromString(string(<char *> grammar))
* #sgml = '<seg grammar="%s">%s</seg>' % (grammar, sentence.encode('utf8'))
* sgml = sentence.strip().encode('utf8') # <<<<<<<<<<<<<<
* cdef decoder.BasicObserver observer = decoder.BasicObserver()
* self.dec.Decode(string(<char *>sgml), &observer)
*/
- __pyx_k_tuple_7 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 73; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_k_tuple_7 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(((PyObject *)__pyx_k_tuple_7));
__Pyx_INCREF(((PyObject *)__pyx_n_s__utf8));
PyTuple_SET_ITEM(__pyx_k_tuple_7, 0, ((PyObject *)__pyx_n_s__utf8));
__Pyx_GIVEREF(((PyObject *)__pyx_n_s__utf8));
__Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_7));
- /* "_cdec.pyx":90
+ /* "_cdec.pyx":100
* hypergraph.ViterbiESentence(self.hg[0], &trans)
* cdef str sentence = GetString(trans).c_str()
* return sentence.decode('utf8') # <<<<<<<<<<<<<<
*
- * """
+ * def viterbi_tree(self):
*/
- __pyx_k_tuple_8 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_k_tuple_8 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(((PyObject *)__pyx_k_tuple_8));
__Pyx_INCREF(((PyObject *)__pyx_n_s__utf8));
PyTuple_SET_ITEM(__pyx_k_tuple_8, 0, ((PyObject *)__pyx_n_s__utf8));
__Pyx_GIVEREF(((PyObject *)__pyx_n_s__utf8));
__Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_8));
+
+ /* "_cdec.pyx":105
+ * assert (self.hg != NULL)
+ * cdef str tree = hypergraph.ViterbiETree(self.hg[0]).c_str()
+ * return tree.decode('utf8') # <<<<<<<<<<<<<<
+ *
+ * def kbest(self, size):
+ */
+ __pyx_k_tuple_9 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_9));
+ __Pyx_INCREF(((PyObject *)__pyx_n_s__utf8));
+ PyTuple_SET_ITEM(__pyx_k_tuple_9, 0, ((PyObject *)__pyx_n_s__utf8));
+ __Pyx_GIVEREF(((PyObject *)__pyx_n_s__utf8));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_9));
+
+ /* "_cdec.pyx":117
+ * if not derivation: break
+ * tree = GetString(derivation._yield).c_str()
+ * yield tree.decode('utf8') # <<<<<<<<<<<<<<
+ * del derivations
+ *
+ */
+ __pyx_k_tuple_10 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_10));
+ __Pyx_INCREF(((PyObject *)__pyx_n_s__utf8));
+ PyTuple_SET_ITEM(__pyx_k_tuple_10, 0, ((PyObject *)__pyx_n_s__utf8));
+ __Pyx_GIVEREF(((PyObject *)__pyx_n_s__utf8));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_10));
+
+ /* "_cdec.pyx":130
+ * if not derivation: break
+ * sentence = GetString(derivation._yield).c_str()
+ * yield sentence.decode('utf8') # <<<<<<<<<<<<<<
+ * del derivations
+ *
+ */
+ __pyx_k_tuple_11 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 130; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_11));
+ __Pyx_INCREF(((PyObject *)__pyx_n_s__utf8));
+ PyTuple_SET_ITEM(__pyx_k_tuple_11, 0, ((PyObject *)__pyx_n_s__utf8));
+ __Pyx_GIVEREF(((PyObject *)__pyx_n_s__utf8));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_11));
+
+ /* "_cdec.pyx":147
+ * for k in range(hypos.size()):
+ * sentence = GetString(hypos[0][k].words).c_str()
+ * yield sentence.decode('utf8') # <<<<<<<<<<<<<<
+ * del hypos
+ *
+ */
+ __pyx_k_tuple_12 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 147; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_12));
+ __Pyx_INCREF(((PyObject *)__pyx_n_s__utf8));
+ PyTuple_SET_ITEM(__pyx_k_tuple_12, 0, ((PyObject *)__pyx_n_s__utf8));
+ __Pyx_GIVEREF(((PyObject *)__pyx_n_s__utf8));
+ __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_12));
__Pyx_RefNannyFinishContext();
return 0;
__pyx_L1_error:;
@@ -3387,27 +5352,39 @@ PyMODINIT_FUNC PyInit__cdec(void)
/*--- Variable export code ---*/
/*--- Function export code ---*/
/*--- Type init code ---*/
- if (PyType_Ready(&__pyx_type_5_cdec_Weights) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 12; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- if (__Pyx_SetAttrString(__pyx_m, "Weights", (PyObject *)&__pyx_type_5_cdec_Weights) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 12; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (PyType_Ready(&__pyx_type_5_cdec_Weights) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (__Pyx_SetAttrString(__pyx_m, "Weights", (PyObject *)&__pyx_type_5_cdec_Weights) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__pyx_ptype_5_cdec_Weights = &__pyx_type_5_cdec_Weights;
- if (PyType_Ready(&__pyx_type_5_cdec_Decoder) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 35; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- if (__Pyx_SetAttrString(__pyx_m, "Decoder", (PyObject *)&__pyx_type_5_cdec_Decoder) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 35; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (PyType_Ready(&__pyx_type_5_cdec_Decoder) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (__Pyx_SetAttrString(__pyx_m, "Decoder", (PyObject *)&__pyx_type_5_cdec_Decoder) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__pyx_ptype_5_cdec_Decoder = &__pyx_type_5_cdec_Decoder;
- if (PyType_Ready(&__pyx_type_5_cdec_Hypergraph) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
- if (__Pyx_SetAttrString(__pyx_m, "Hypergraph", (PyObject *)&__pyx_type_5_cdec_Hypergraph) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (PyType_Ready(&__pyx_type_5_cdec_Hypergraph) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (__Pyx_SetAttrString(__pyx_m, "Hypergraph", (PyObject *)&__pyx_type_5_cdec_Hypergraph) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__pyx_ptype_5_cdec_Hypergraph = &__pyx_type_5_cdec_Hypergraph;
- if (PyType_Ready(&__pyx_Generator_type) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (PyType_Ready(&__pyx_type_5_cdec_Lattice) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 154; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (__Pyx_SetAttrString(__pyx_m, "Lattice", (PyObject *)&__pyx_type_5_cdec_Lattice) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 154; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_ptype_5_cdec_Lattice = &__pyx_type_5_cdec_Lattice;
+ if (PyType_Ready(&__pyx_Generator_type) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__pyx_ptype_5_cdec___pyx_Generator = &__pyx_Generator_type;
__pyx_type_5_cdec___pyx_scope_struct____iter__.tp_base = __pyx_ptype_5_cdec___pyx_Generator;
- if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct____iter__) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct____iter__) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__pyx_ptype_5_cdec___pyx_scope_struct____iter__ = &__pyx_type_5_cdec___pyx_scope_struct____iter__;
+ __pyx_type_5_cdec___pyx_scope_struct_1_kbest.tp_base = __pyx_ptype_5_cdec___pyx_Generator;
+ if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_1_kbest) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_ptype_5_cdec___pyx_scope_struct_1_kbest = &__pyx_type_5_cdec___pyx_scope_struct_1_kbest;
+ __pyx_type_5_cdec___pyx_scope_struct_2_kbest_tree.tp_base = __pyx_ptype_5_cdec___pyx_Generator;
+ if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_2_kbest_tree) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 120; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_ptype_5_cdec___pyx_scope_struct_2_kbest_tree = &__pyx_type_5_cdec___pyx_scope_struct_2_kbest_tree;
+ __pyx_type_5_cdec___pyx_scope_struct_3_sample.tp_base = __pyx_ptype_5_cdec___pyx_Generator;
+ if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_3_sample) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 137; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_ptype_5_cdec___pyx_scope_struct_3_sample = &__pyx_type_5_cdec___pyx_scope_struct_3_sample;
/*--- Type import code ---*/
/*--- Variable import code ---*/
/*--- Function import code ---*/
/*--- Execution code ---*/
- /* "_cdec.pyx":7
- * cimport decoder
+ /* "_cdec.pyx":10
+ * cimport kbest as kb
*
* SetSilent(True) # <<<<<<<<<<<<<<
*
@@ -3415,47 +5392,47 @@ PyMODINIT_FUNC PyInit__cdec(void)
*/
SetSilent(1);
- /* "_cdec.pyx":9
+ /* "_cdec.pyx":12
* SetSilent(True)
*
* class ParseFailed(Exception): # <<<<<<<<<<<<<<
* pass
*
*/
- __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 12; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(((PyObject *)__pyx_t_1));
- __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 12; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(((PyObject *)__pyx_t_2));
__Pyx_INCREF(__pyx_builtin_Exception);
PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_builtin_Exception);
__Pyx_GIVEREF(__pyx_builtin_Exception);
- __pyx_t_3 = __Pyx_CreateClass(((PyObject *)__pyx_t_2), ((PyObject *)__pyx_t_1), __pyx_n_s__ParseFailed, __pyx_n_s___cdec); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = __Pyx_CreateClass(((PyObject *)__pyx_t_2), ((PyObject *)__pyx_t_1), __pyx_n_s__ParseFailed, __pyx_n_s___cdec); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 12; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_3);
__Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
- if (PyObject_SetAttr(__pyx_m, __pyx_n_s__ParseFailed, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (PyObject_SetAttr(__pyx_m, __pyx_n_s__ParseFailed, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 12; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
__Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
- /* "_cdec.pyx":53
+ /* "_cdec.pyx":56
*
* @classmethod
* def fromconfig(cls, ini): # <<<<<<<<<<<<<<
* cdef dict config = {}
* with open(ini) as fp:
*/
- __pyx_t_1 = __Pyx_GetName((PyObject *)__pyx_ptype_5_cdec_Decoder, __pyx_n_s__fromconfig); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_1 = __Pyx_GetName((PyObject *)__pyx_ptype_5_cdec_Decoder, __pyx_n_s__fromconfig); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
- __pyx_t_3 = __Pyx_Method_ClassMethod(__pyx_t_1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ __pyx_t_3 = __Pyx_Method_ClassMethod(__pyx_t_1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_3);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
- if (PyDict_SetItem((PyObject *)__pyx_ptype_5_cdec_Decoder->tp_dict, __pyx_n_s__fromconfig, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+ if (PyDict_SetItem((PyObject *)__pyx_ptype_5_cdec_Decoder->tp_dict, __pyx_n_s__fromconfig, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
PyType_Modified(__pyx_ptype_5_cdec_Decoder);
/* "_cdec.pyx":1
* from libcpp.string cimport string # <<<<<<<<<<<<<<
* from libcpp.vector cimport vector
- * from utils cimport *
+ * from cython.operator cimport dereference as deref
*/
__pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(((PyObject *)__pyx_t_3));
diff --git a/python/src/_cdec.pyx b/python/src/_cdec.pyx
index b99f087d..45320c46 100644
--- a/python/src/_cdec.pyx
+++ b/python/src/_cdec.pyx
@@ -1,8 +1,11 @@
from libcpp.string cimport string
from libcpp.vector cimport vector
+from cython.operator cimport dereference as deref
from utils cimport *
cimport hypergraph
cimport decoder
+cimport lattice
+cimport kbest as kb
SetSilent(True)
@@ -16,13 +19,13 @@ cdef class Weights:
self.weights = &decoder.dec.CurrentWeightVector()
def __getitem__(self, char* fname):
- cdef unsigned fid = Convert(fname)
+ cdef unsigned fid = FDConvert(fname)
if fid <= self.weights.size():
return self.weights[0][fid]
raise KeyError(fname)
def __setitem__(self, char* fname, float value):
- cdef unsigned fid = Convert(<char *>fname)
+ cdef unsigned fid = FDConvert(<char *>fname)
if self.weights.size() <= fid:
self.weights.resize(fid + 1)
self.weights[0][fid] = value
@@ -30,7 +33,7 @@ cdef class Weights:
def __iter__(self):
cdef unsigned fid
for fid in range(1, self.weights.size()):
- yield Convert(fid).c_str(), self.weights[0][fid]
+ yield FDConvert(fid).c_str(), self.weights[0][fid]
cdef class Decoder:
cdef decoder.Decoder* dec
@@ -66,6 +69,7 @@ cdef class Decoder:
fname, value = line.split()
self.weights[fname.strip()] = float(value)
+ # TODO: list, lattice translation
def translate(self, unicode sentence, grammar=None):
if grammar:
self.dec.SetSentenceGrammarFromString(string(<char *> grammar))
@@ -81,6 +85,12 @@ cdef class Decoder:
cdef class Hypergraph:
cdef hypergraph.Hypergraph* hg
+ cdef MT19937* rng
+
+ def __dealloc__(self):
+ del self.hg
+ if self.rng != NULL:
+ del self.rng
def viterbi(self):
assert (self.hg != NULL)
@@ -89,6 +99,77 @@ cdef class Hypergraph:
cdef str sentence = GetString(trans).c_str()
return sentence.decode('utf8')
+ def viterbi_tree(self):
+ assert (self.hg != NULL)
+ cdef str tree = hypergraph.ViterbiETree(self.hg[0]).c_str()
+ return tree.decode('utf8')
+
+ def kbest(self, size):
+ assert (self.hg != NULL)
+ cdef kb.KBestDerivations[vector[WordID], kb.ESentenceTraversal]* derivations = new kb.KBestDerivations[vector[WordID], kb.ESentenceTraversal](self.hg[0], size)
+ cdef kb.KBestDerivations[vector[WordID], kb.ESentenceTraversal].Derivation* derivation
+ cdef str tree
+ cdef unsigned k
+ for k in range(size):
+ derivation = derivations.LazyKthBest(self.hg.nodes_.size() - 1, k)
+ if not derivation: break
+ tree = GetString(derivation._yield).c_str()
+ yield tree.decode('utf8')
+ del derivations
+
+ def kbest_tree(self, size):
+ assert (self.hg != NULL)
+ cdef kb.KBestDerivations[vector[WordID], kb.ETreeTraversal]* derivations = new kb.KBestDerivations[vector[WordID], kb.ETreeTraversal](self.hg[0], size)
+ cdef kb.KBestDerivations[vector[WordID], kb.ETreeTraversal].Derivation* derivation
+ cdef str sentence
+ cdef unsigned k
+ for k in range(size):
+ derivation = derivations.LazyKthBest(self.hg.nodes_.size() - 1, k)
+ if not derivation: break
+ sentence = GetString(derivation._yield).c_str()
+ yield sentence.decode('utf8')
+ del derivations
+
+ def intersect(self, Lattice lat):
+ assert (self.hg != NULL)
+ hypergraph.Intersect(lat.lattice[0], self.hg)
+
+ def sample(self, unsigned n):
+ assert (self.hg != NULL)
+ cdef vector[hypergraph.Hypothesis]* hypos = new vector[hypergraph.Hypothesis]()
+ if self.rng == NULL:
+ self.rng = new MT19937()
+ hypergraph.sample_hypotheses(self.hg[0], n, self.rng, hypos)
+ cdef str sentence
+ cdef unsigned k
+ for k in range(hypos.size()):
+ sentence = GetString(hypos[0][k].words).c_str()
+ yield sentence.decode('utf8')
+ del hypos
+
+ # TODO: get feature expectations, get partition function ("inside" score)
+ # TODO: reweight the forest with different weights (Hypergraph::Reweight)
+ # TODO: inside-outside pruning
+
+cdef class Lattice:
+ cdef lattice.Lattice* lattice
+
+ def __init__(self, tuple plf_tuple):
+ self.lattice = new lattice.Lattice()
+ cdef bytes plf = str(plf_tuple)
+ hypergraph.PLFtoLattice(string(<char *>plf), self.lattice)
+
+ def __str__(self):
+ return hypergraph.AsPLF(self.lattice[0]).c_str()
+
+ def __iter__(self):
+ return iter(eval(str(self)))
+
+ def __dealloc__(self):
+ del self.lattice
+
+# TODO: wrap SparseVector
+
"""
def params_str(params):
return '\n'.join('%s=%s' % (param, value) for param, value in params.iteritems())
diff --git a/python/src/hypergraph.pxd b/python/src/hypergraph.pxd
index 05977fa8..4aef6955 100644
--- a/python/src/hypergraph.pxd
+++ b/python/src/hypergraph.pxd
@@ -1,10 +1,41 @@
from libcpp.string cimport string
from libcpp.vector cimport vector
-from utils cimport WordID
+from utils cimport *
+cimport lattice
cdef extern from "decoder/hg.h":
cdef cppclass Hypergraph:
+ cppclass Node:
+ int id_
+ WordID cat_
+ WordID NT()
+ #EdgesVector in_edges_
+ #EdgesVector out_edges_
Hypergraph(Hypergraph)
+ vector[Node] nodes_
cdef extern from "decoder/viterbi.h":
- cdef string ViterbiESentence(Hypergraph hg, vector[WordID]* trans)
+ cdef prob_t ViterbiESentence(Hypergraph hg, vector[WordID]* trans)
+ cdef string ViterbiETree(Hypergraph hg)
+
+cdef extern from "decoder/hg_io.h" namespace "HypergraphIO":
+ bint ReadFromJSON(istream* inp, Hypergraph* out)
+ bint WriteToJSON(Hypergraph hg, bint remove_rules, ostream* out)
+
+ #void WriteAsCFG(Hypergraph hg)
+ #void WriteTarget(string base, unsigned sent_id, Hypergraph hg)
+
+ void ReadFromPLF(string inp, Hypergraph* out, int line=*)
+ string AsPLF(Hypergraph hg, bint include_global_parentheses=*)
+ string AsPLF(lattice.Lattice lat, bint include_global_parentheses=*)
+ void PLFtoLattice(string plf, lattice.Lattice* pl)
+
+cdef extern from "decoder/hg_intersect.h" namespace "HG":
+ bint Intersect(lattice.Lattice target, Hypergraph* hg)
+
+cdef extern from "decoder/hg_sampler.h" namespace "HypergraphSampler":
+ cdef cppclass Hypothesis:
+ vector[WordID] words
+ SparseVector[double] fmap
+ prob_t model_score
+ void sample_hypotheses(Hypergraph hg, unsigned n, MT19937* rng, vector[Hypothesis]* hypos)
diff --git a/python/src/kbest.pxd b/python/src/kbest.pxd
new file mode 100644
index 00000000..e339714a
--- /dev/null
+++ b/python/src/kbest.pxd
@@ -0,0 +1,16 @@
+from libcpp.vector cimport vector
+from utils cimport WordID
+cimport hypergraph
+
+cdef extern from "decoder/viterbi.h":
+ cdef cppclass ESentenceTraversal:
+ pass
+ cdef cppclass ETreeTraversal:
+ pass
+
+cdef extern from "decoder/kbest.h" namespace "KBest":
+ cdef cppclass KBestDerivations[T, Traversal]:
+ cppclass Derivation:
+ T _yield "yield"
+ KBestDerivations(hypergraph.Hypergraph hg, unsigned k)
+ Derivation* LazyKthBest(unsigned v, unsigned k)
diff --git a/python/src/lattice.pxd b/python/src/lattice.pxd
new file mode 100644
index 00000000..bdfaba80
--- /dev/null
+++ b/python/src/lattice.pxd
@@ -0,0 +1,16 @@
+from libcpp.vector cimport vector
+from utils cimport WordID
+
+cdef extern from "decoder/lattice.h":
+ cdef cppclass LatticeArc:
+ WordID label
+ double cost
+ int dist2next
+ LatticeArc()
+ LatticeArc(WordID w, double c, int i)
+
+ cdef cppclass Lattice: # (vector[vector[LatticeArc]])
+ Lattice()
+ Lattice(unsigned t)
+ Lattice(unsigned t, vector[LatticeArc] v)
+ bint IsSentence()
diff --git a/python/src/utils.pxd b/python/src/utils.pxd
index ae38948e..786cd265 100644
--- a/python/src/utils.pxd
+++ b/python/src/utils.pxd
@@ -4,20 +4,29 @@ from libcpp.vector cimport vector
cdef extern from "<iostream>" namespace "std":
cdef cppclass istream:
pass
+ cdef cppclass ostream:
+ pass
cdef cppclass istringstream(istream):
istringstream(char*)
-cdef extern from "utils/filelib.h":
- cdef cppclass ReadFile:
- ReadFile(string)
- istream* stream()
-
cdef extern from "utils/weights.h":
ctypedef double weight_t
+cdef extern from "utils/logval.h":
+ cdef cppclass LogVal[T]:
+ pass
+
+cdef extern from "utils/prob.h":
+ cdef cppclass prob_t:
+ pass
+
cdef extern from "utils/wordid.h":
ctypedef int WordID
+cdef extern from "utils/sparse_vector.h":
+ cdef cppclass SparseVector[T]:
+ pass
+
cdef extern from "utils/tdict.cc" namespace "TD":
cdef string GetString(vector[WordID] st)
@@ -25,5 +34,20 @@ cdef extern from "utils/verbose.h":
cdef void SetSilent(bint)
cdef extern from "utils/fdict.h" namespace "FD":
- WordID Convert(char*)
- string& Convert(WordID)
+ WordID FDConvert "FD::Convert" (char*)
+ string& FDConvert "FD::Convert" (WordID)
+
+cdef extern from "utils/filelib.h":
+ cdef cppclass ReadFile:
+ ReadFile(string)
+ istream* stream()
+
+cdef extern from "utils/sampler.h":
+ cdef cppclass MT19937:
+ pass
+
+"""
+cdef extern from "<boost/shared_ptr.hpp>" namespace "boost":
+ cdef cppclass shared_ptr[T]:
+ void reset(T*)
+"""
diff --git a/python/test.py b/python/test.py
index df5ce64d..1542dd4f 100644
--- a/python/test.py
+++ b/python/test.py
@@ -6,12 +6,44 @@ config = 'formalism=scfg'
weights = '../tests/system_tests/australia/weights'
grammar_file = '../tests/system_tests/australia/australia.scfg.gz'
+# Load decoder width configuration
decoder = cdec.Decoder(config)
+# Read weights
decoder.read_weights(weights)
+
print dict(decoder.weights)
+
+# Read grammar
with gzip.open(grammar_file) as f:
grammar = f.read()
+
+# Input sentence
sentence = u'澳洲 是 与 北韩 有 邦交 的 少数 国家 之一 。'
print 'Input:', sentence
+
+# Decode
forest = decoder.translate(sentence, grammar=grammar)
-print 'Output:', forest.viterbi().encode('utf8')
+
+# Get viterbi translation
+print 'Output[0]:', forest.viterbi().encode('utf8')
+print ' Tree[0]:', forest.viterbi_tree().encode('utf8')
+
+# Get k-best translations
+for i, (sentence, tree) in enumerate(zip(forest.kbest(5), forest.kbest_tree(5)), 1):
+ print 'Output[%d]:' % i, sentence.encode('utf8')
+ print ' Tree[%d]:' % i, tree.encode('utf8')
+
+# Sample translations from the forest
+for sentence in forest.sample(5):
+ print 'Sample:', sentence.encode('utf8')
+
+# Reference lattice
+lattice = ((('australia',0,1),),(('is',0,1),),(('one',0,1),),(('of',0,1),),(('the',0,4),('a',0,4),('a',0,1),('the',0,1),),(('small',0,1),('tiny',0,1),('miniscule',0,1),('handful',0,2),),(('number',0,1),('group',0,1),),(('of',0,2),),(('few',0,1),),(('countries',0,1),),(('that',0,1),),(('has',0,1),('have',0,1),),(('diplomatic',0,1),),(('relations',0,1),),(('with',0,1),),(('north',0,1),),(('korea',0,1),),(('.',0,1),),)
+
+lat = cdec.Lattice(lattice)
+assert (lattice == tuple(lat))
+
+# Intersect forest and lattice
+forest.intersect(lat)
+# Get best synchronous parse
+print forest.viterbi_tree()